JPA differentiating id GenerationType using inheritance

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 would define two different persistence units, one for each database. Then you can customize one with an orm.xml file.

Need Your Help

YUI Autocomplete renders under other page elements in IE7

css internet-explorer-7 yui z-index

I'm working now on a page that has a column of boxes styled with sexy shadows and corners and whatnot using the example here. I have to admit, I don't fully understand how that CSS works, but it l...

NHibernate HQL join column

c# nhibernate hql

I looked into nhibernate joins and couldn't figure out how the joins are performed. In the examples it doesn't provide the columns on which to perform the joins. Are these performed automatically b...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.