jpa

JPA Typed Search Queries

I have a rather big model Applicant: public class Applicant{ private Long id private String name; ... ... } To populate a selection list, I need a list of (id, name) tuples and I use this search query: public List getNames() { Query query = em.createQuery("select a.id, a.name from Applicant a"); return query.getResultL...

Constraint violation in Hibernate unidirectional OneToMany mapping with JoinTable and OrderColumn when removing elements

Hi, I have a problem when removing elements from a list mapped as described above. Here is the mapping: @Entity @Table( name = "foo") class Foo { private List bars; @OneToMany @OrderColumn( name = "order_index" ) @JoinTable( name = "foo_bar_map", joinColumns = @JoinColumn( name = "foo_id" ), inverseJoinColumns = @Jo...

how to associate single entity to multiple entities(pojo classes)

hello, does anyone here knows the correct way of associating a single entity(a pojo class) to multiple classes.. im currently working on a situation where mainClass has a one-to-many relationship to subClass and subClass has one-to-many relationship to unitsClass too. the relationship of these classes looks like this: mainClass - oneTo...

JPA/Hibernate: What's better for composite primary keys, @IdClass or @EmbeddedId implementations and why?

Hello, what's better for JPA/Hibernate composite primary keys, @IdClass or @EmbeddedId implementations and why? This is an intentionally naive question. I decided to use @EmbeddedId (for whatever reason) and I feel like I made the wrong choice. Dereferencing the embeddedId that contains the column properties is redundant and quite erro...

How to tell EclipseLink to use full table names for aliases in SQL

EclipseLink normally generates SQLs like: SELECT t0.ID, t1.NAME FROM MAN t0, WIFE t1 WHERE t0.ID = t1.MAN_ID Is it possible to tell EclipseLink, that it should use full table names for aliases to make the query more readable? SELECT t0_MAN.ID, t1_WIFE.NAME FROM MAN t0_MAN, WIFE t1_WIFE WHERE t0_MAN.ID = t1_WIFE.MAN_ID I think Hiber...

Does JPA support a kind of "Any" mapping for embeddable objects?

Hi, I'm extending the data model of an Java application to include some kind of a setting facility. Settings in this application would basically be Strings or Numbers, no entities or other model objects. My Question is what's the best way to map this requirement to JPA (Hibernate)? I first thought about implementing a Setting class wi...

How do I properly cascade save a one-to-one, bidirectional relationship on primary key in Hibernate 3.6

I have an one-to-one, bidirectional entity relationship with shared keys. When I attempt to save the owner of the association I get a "null id generated" exception against the owned side of the relationship. I am utilizing hibernate-entitymanager and using spring for transaction management. Owning Entity @Entity @Table(name = "lead") p...

Advanced search

We are going to provide an advanced search option on a system that will let users find events that matches a name (textual search), have on or more tags assigned to it and that will start before or after a given date. Should I consider using hibernate search or something similar? Or should I just generate some jpql queries to get that s...

Avoid 1 level cache issues while using @PersistenceContext(type=PersistenceContextType.EXTENDED)

I just configured @PersistenceContext(type=PersistenceContextType.EXTENDED) on my DAO classes to get lazy loading working on the view layer (needed to get it not closing the session for this) but I am having issues with 1 level cache (I imagine).. Because the object is cached even with my second level cache settings off. After turned off...

JPA: Entity X has a OneToMany relationship to itself. How?

I have one Entity call Comment Comment + id (PK) + fromUserId + targetId + replyId : This is the foreign key to id The idea is a comment can have many replies, but a reply is also a comment. To distinguish between the two, a comment will have replyId equal -1, meanwhile a reply will have a non -1 value for replyId. Ultimately, what I...

JPA/Hibernate : @PersistenceContext unitName has multiple matches error...

Hi all, I am working on a project and so far it went quite well until I have checked out the latest changes from another team, to work on a most up to date files ( do not concentrate on that one ). I am working using Tomcat OpenEJB 3.1, JPA and Hibernate 3.2.6. What is the problem, after the deployment of application it gets stuck on : ...

Why does eclipselink consume the whole allocationSize each time it's rebooted?

I've just noticed that for my entity's id, eclipselink assigns an id 1 + the previously greated assigned IN THE SAME SESSION (1), as opposed to in the element table (2). This goes against my application expectations. What's the easiest way to tell it to do 2? @Id @GeneratedValue(strategy = GenerationType.AUTO) private int objId; And...

OpenEJB with Tomcat and Hibernate and JPA

Hi there! I'm using OpenEJB 3.1.3 embedded in Tomcat 5.5.26 and I use hibernate 3.6 as a JPA provider. Here's my persistence.xml: <?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

JPA many to many with extra column

Hi buddies. I have a following problem that I need to solve. The core issues is that I want to add additional column into JoinTable for ManyToMany relation in JPA. In my case I have following entities. The Topic is a simple entity which has many RemoteDocument's (one RemoteDocument may be refered by many Topic's, hence it should be Many...

JPA mapping classes (openjpa)

Let's say I have a Question and QuestionHeader class. Question extends QuestionHeader. My mapping looks like this: <entity class="hr.leads.services.model.jpa.QuestionHeader"> <table name="question" /> <inheritance strategy="SINGLE_TABLE" /> <attributes> <basic name="description"> <column name="description...

How to define polymorphism in JPA

Hi, there is a situation. For example, I am designing simple blog. There are articles and photographies. Users can add their comment to both of them. So when I write it in Java, it looks like this: public interface Commentable { ... } public class Article implements Commentable { ... } public class Photo implements Commentable { ... ...

Retrieving a child object after a commit on an entity object

Lets say I retrieve an entity object that looks like this: @Entity public class Mother { ... @OneToMany(mappedBy = "mother", targetEntity = Child.class, fetch = FetchType.LAZY) public List<Child> getChildren() { return children; } } When retrieving the above object, I commit the t...

Possible to upgrade jboss 5.1 jpa1 to jpa 2

Is it possible to upgrade Hibernate/JPA that is shipped with JBoss 5.1 to use JPA 2.0? I am interested in making use of the OrderColumn. I am unable to upgrade JBoss to the latest version - 6 ...

Committing a database change in isolation to the main transaction

Let's say I have the following code: public void doSomething() { // begin transaction // do stuff 1 ... // update a row which must be committed now ... // do stuff 2 ... // commit transaction } I've kept the large amount of work on the database in the one method to simplify the pseudo code. However...

Stateless EJB JPA Error

My project is based on Netbeans 6.9 ,JEE 6 Web Application with Stateless EJB, REST Services. There is a big problem while doing the transaction. 1) Using JPA: JPA is not pushing the values to the db table after persist/flush. But entity ID is populated. I'm not able to the same db - entity in the other application. Ideally it should pu...