I've been trying to work out the correct way of annotating an entity in an Oracle database so that Hibernate will let the database give it an identity, and then select it to find out what ID it's been assigned.
Caveat: we need the same annotation to work for both Oracle and SQL Server. On Oracle there's a sequence and a before-insert trigger; on SQL Server the field is an ident field which is auto-incremented.
Using the "AUTO" generator type, Hibernate selects from hibernate_sequence and then does the insert using that - the trigger overwrites the value, and everyone gets confused.
Removing the trigger is a possibility, although in that case I'd like to be able to specify the sequence to use when on Oracle, without any complaints when running on SQL Server, if possible. (It helps to have different sequences for debugging purposes - on a small test system, any ID between 17001 and 18000 always belongs to one table, etc.)
I *believe* (although I haven't tried it yet) that a generator type of "select" in the XML configuration for Hibernate would do the right thing - is there an equivalent of this in Annotations-land?
Currently we're using Annotations 3.0 preview release 2, but if that's a problem we could probably change. I've looked in the Hibernate Annotations docs and the EJB 3.0 public draft, but to no avail... apologies if I've missed the answer!
Please let me know if you need any more information.
Thanks in advance.
|