I am usingHibernate version: 3.3.1 (Annotations 3.2.2)
I have classes that are stored on a server database (MySQL). These classes are serialized and sent to a client, where they are to be put into a local database (Derby 10.2.2.0).
The classes contain annotations for generating an identity column. However on the client, the identity value has to be the same as on the server. When I add the received objects, Hibernate generates a new ID value, and (of course) throws an exception if I try to change it later.
Code:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ID", nullable = false)
private Integer id = null;
What I need is a way of overriding the annotation on the client, or forcing Hibernate to accept the incoming ID. I would like to use JPA standard things only because sometimes I have to use these classes with other frameworks (like Toplink).
There is a way out - if I can't find anything else - and that is to generate the ID's myself when new records are inserted on the server (and remove the @GeneratedValue). However I prefer not to do this if possible.