I would like to call upon the
Java community for a rather specific problem I've been unable to resolve for a while now using the following setup:
- Weblogic 10
- JRE 1.6.05 (well actually JRockit)
-
JEE 5.0
-
Struts 1.2.x
- JPA with Hibernate 3.2.5.ga as provider
- Oracle 10g
My problem is persisting a new entity (ie. no @Id set when the object is persisted). I was using Weblogic's default implementation of JPA (OpenJPA/Kodo) and persisting new objects works just fine as per:
Entity snippet:
DAO snippet:
Yeah the summaryId is a
String (in reality a numeric value). Anyway, with the OpenJPA provider, this works wonderfully for inserting new entities to the database. However, when I switched to Hibernate, immediately my inserts started failing with exceptions complaining that I cannot insert this entity without first setting the Primary Key.
Oracle has the following trigger which selects the next value from the sequence for the Summaries table before an insert, and stuffs it into the insert:
I want to avoid using any @GeneratedValue, @SequenceGenerator, @TableGenerator, etc, etc annotations, since our DBAs will be less than pleased if I tell them I want my application to manage primary keys & their sequences itself. How can I force Hibernate (or JPA, really) to perform the insert without trying to manage the PK field? OpenJPA seemed to have no problems inserting an entity and then retrieving it's PK... Arg.
Any ideas? I've been researching this issue for a while now, with no success (I could use some sequence generator annotations, but again, my DBAs want the triggers to handle the PK generation. Furthermore, the sequence is not even visible to the username our application uses to access the DB, so this approach will require more changes to the DB).
Cheers & Regards,
Edward