I'm using JPA (Hibernate implementation) to save objects to the database. Selecting works fine, but for some reason, saving doesn't work. I don't get any errors, but the database doesn't get changed either. This goes for both new entities and existing ones.
EPayment pay = new EPayment();
pay.setAmount(payment.getAmount());
...
pay.s...
I'm using a convention of prefixing field names with an underscore. When I generate annotate entity classes with such fields I am stuck to using the underscore-prefixed property names in queries. I want to avoid that, and be able to do:
@Entity
public class Container {
private String _value;
}
// in a lookup method
executeQuery("f...
For a parent-child entity relationship, when (and why) would you use a DAO interface for only the parent and when would you make also make DAO for the children? To me, it makes sense to only make a DAO for the parent if the Children MUST belong to a parent and should not exist as orphans.
So if I wanted to delete a Child, I would modif...
Hi,
I would like to have an entity named "GROUP" in my JPA setup. Now I get problems when I try to perform JPA queries, like "select count(group_.id) from Group group_".
JPA thinks this is a misplaced GROUP BY attempt and complains. Is there a way I can escape "Group", or do I have to rename my table?
Thx!
...
I have a class I am not sure how to annotate properly.
My goal for Holder::data:
List should maintain order not by comparator but by the natural ordering of the elements in the array. (Which can be an ndx column if that is helpful.)
Holder will have the only reference to data, so Cascade all is probably applicable as well.
I am al...
I have a method that retrieves Entities using a NamedQuery. I update a value of each entity and then run another named query (in the same method and Transaction) filtering by the old value and it returns the same Entities as if I had not changed them.
I understand that the EntityManager needs to be flushed and also that it should happen...
(How) is it possible to persist a JPA Entity at the databases of multiple servers without copying everything to DTOs?
We have a distributed system. Some applications do have DBs for caching purposes. The JPA Provider throws an Exception in which it complains that it cannot persist a detached object.
But I would like to preserve the ID ...
My web application is using Java, Hibernate's JPA implementation (EntityManager) and Spring. What are my logger choices and what would you recommend. Ideally the configuration would be simple (one config file for Hibernate, Spring and my code).
...
I am mapping my database tables to my java objects. Generally I name my tables in the plural form in that a table holding books information is called BOOKS. The java object represents however one book and should be called Book. Similarly for AUTHORS/Author etc.
On the other hand, its kind of simplistic to give the same to the domain ob...
I have a simple question about usage of Hibernate. I keep seeing people using JPA annotations in one of two ways by annotating the fields of a class and also by annotating the get method on the corresponding beans.
My question is as follows: Is there a difference between annotating fields and bean methods with JPA annoations such as @I...
I have two fields of an entity class which I don't want to be unique but to instead be used as composite fields for a key which must itself be unique. For example I have two fields (name and version) which can be the same for other records but together they must be unique. What is the best way to do that using Hibernate (with annotatio...
Hi gang,
My team has two classes, User and Store, related by JPA @ManyToMany annotations. The relevant code is below.
When creating a new User object and setting its stores, life is good. But we're seeing some unexpected behavior when trying to update User objects through our Struts 2 / Spring web UI. (These problems do not occur whe...
Hey fellows,
Because calling a flush() to get every entities persist from memory to database. So if I use call too much unnecessary flush(), it could take much time therefore not a good choice for the performance. Here is a scenario that I don't know when to call a flush()?
//Order and Item have Bidirectional Relationships
Order ord = ...
If I create a Customer and Controller, then associate my Controller with a customer it saves fine.
If I then remove my controller it doesn't remove the relationship between them.
This causes an EntityNotFoundException when I load the Customer.
javax.persistence.EntityNotFoundException: Unable to find Controller with id 22
I'd like to...
When I annotate a class with @Entity and try to resolve the dependencies, I get to choose the package between two different packages, javax.persistence.Entity and org.hibernate.annotations.Entity
The javax package is JPA's entity-annotation, but why is there a hibernate entity-annotation and difference does it have with JPA's annotation...
Bear with me as I try to simplify my issue as much as possible.
I am creating a new ORM object. This object has an auto generated primary key which is created on the database using as an identity. Within this object, is a child object with a many to one relationship with the parent object. One of the attributes I need to set to create t...
The following doesn't work:
@Entity
class Owner {
@OneToMany(mappedBy="owner", cascade = {CascadeType.ALL})
protected Set<B> getBSet() {
..
}
}
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
class A {
@ManyToOne
public Owner getOwner() {
...
}
}
@Entity
class B extends A {
}
It causes an exception a...
Hi, I'm running into a null pointer exception if I try to use the following code:
//Spring JPA entityManager allow us to retriver the underlying session.
org.hibernate.Session session = (org.hibernate.Session)entityManager.getDelegate();
org.hibernate.Session dom4jSession = session.getSession(org.hibernate.EntityMode.DOM4J);
org.hibern...
Hi,
I have the following JPA SqlResultSetMapping:
@SqlResultSetMappings({
@SqlResultSetMapping(name="GroupParticipantDTO",
columns={
@ColumnResult(name="gpId"),
@ColumnResult(name="gpRole"),
// @ColumnResult(name="gpRemarks")
}
)
Which is used like this:
StringBuilder sbQuer...
Hello guys, I am new to openJPA.
I have a scenario where, depending upon the server where my application is running, I need to change the settings to persistance.xml.
For eg. if its running on Server A, then it should use different database(different url), different password etc. and if the application is running on Server B then it sh...