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 didn't find a real solution. What I ended doing was to duplicate the class providing different @Entity(name="name1") and removing for one of them the @GenerationType annotation. In the persistence unit I use the one or the other accordingly to what I'm going to do.