Hello,
I am using hibernate-3.1 and hibernate-annotations-3.1beta6 within a spring container (not as part of a servlet). I have the following situation:
Object x has been made persistent in Database A. The object is very simple, just a few fields and no associations at all. It's id-field is a long value.
Database A is no longer accessible, but I know the entire content of object x from a log-file (including the primary key). I want to create an exact copy in database B (exact meaning that even the id should be the same). Object x is not present in database B yet (there is no row with the same primary key).
I have tried both
session.merge(x);
session.replicate(x,ReplicationMode.OVERWRITE);
In either case, a new row is written successfully into the database,
but the primary key is not the same. However, as I am using this primary key externally for other processes, this causes a problem for me.
I am still very new to Hibernate (I have only used direct JDBC and Versant so far), so I was hoping that anyone could give me a "push" into the right direction ;-) There are several paths I could follow, but I do not really like any of them:
* I could create my own id-generator (which then could consequently manipulate to return the desired id). But why disabling standard hibernate code that works perfectly fine for me in 95% of all cases? Chances are that my code would be less stable and probably less performant.
* I could refactor my system not to use this id-field any more. Besides the fact that it means a lot of work, I just hate the fact that I would have a field that has no valid use in my POJOs besides persistence.
* I could create a second id-field just for Hibernate. Same concern as above. :-(
Since I am still very inexperienced regarding Hibernate, there is probably a better and easier way to do this. Could anyone show it to me, please? Your help is appreciated.
Best regards,
Jens