File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes JPA differentiating id GenerationType using inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPA differentiating id GenerationType using inheritance" Watch "JPA differentiating id GenerationType using inheritance" New topic
Author

JPA differentiating id GenerationType using inheritance

francesco umani
Greenhorn

Joined: Aug 07, 2013
Posts: 27


I have two different databases D1, D2 with a same Table T.

T has a primary Key column id, that is autogenerated in D1, a simple integer in D2. I've to shift record from T in D1 to T in D2, so I mapped T as an @Entity with JPA. The problem is that @ID is @GeneratedValue(strategy = GenerationType.IDENTITY) for D1 but not for D2.

Is there a solution for not duplicating the Entity? I noticed that using a @MappedSuperclass i need an @Id column but in my case is what I'm trying to specialize. The only solution I found is to generate two different classes referencing the same Table that are identical apart from the @id... anything better?

(if I use a common abstract class I've problems when defining @NamedQueries 'cause it seems that inherited field cannot be referenced (SELECT m FROM Specialized m WHERE m.aBaseField= :aBaseField) return an exception : "The state field path 'm.aBaseField' cannot be resolved to a valid type."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA differentiating id GenerationType using inheritance