tags:

views:

108

answers:

3

I want to use JPA for my persistence layer of my Java Desktop Application but I have the similar problem as describe at http://stackoverflow.com/questions/2562746/jpa-entity-design-problem/2563009#2563009

I didn't find a solution to the above kind of problem that's why I want to go with any other alternative of JPA.

It would be better if I get the solution of the above problem.

+5  A: 

IMO the proper way to deal with such issues would be to use a generated internal (typically Long) ID instead of a natural primary key - this eliminates the whole problem. Of course, this requires a modification of your DB schema. I included an example mapping in my answer to the other post.

If this isn't possible, and the referred solution is not satisfactory to you (btw why?), you might try Hibernate, which offers a superset of JPA functionality (although I can't offer a solution with Hibernate out of the top of my head - especially without knowing what your problem is with the JPA solution).

Péter Török
+1  A: 

Things work beautifully if you let jpa assign an id (eg integer) as a primary key for your objects. The complications in the example you mentioned are only because of the constraints that author had on primary keys

John
A: 

As one of the other answers says, generate an "internal" (surrogate) key ... aka "datastore" identity. This is part of the JDO specification (JPA only supports application identity, whereas JDO supports datastore and application identity).

DataNucleus