views:

711

answers:

2

Hi,

How can I generate insert statements like insert into table (sequence.nextval, 'b0) using hibernate?

Hibernate currently selects the sequence.nextval value and only then it uses the value to insert the entry in the table.

Note: I'm not very fond of custom id generators.

A: 

If you're using Oracle 10 client or above, check out sequence-identity in the most recent Hibernate versions to do what you're asking for.

Steve Prior
+1  A: 

Hibernate selects sequence.nextval because it has to return that value back to you (e.g. set ID on your entity). Unless you're doing something very esoteric I strongly doubt this has a big impact on performance (e.g. it's nothing compared to the actual insert). That said, you can look at Hibernate's sequence hi-lo generator - it would only access the sequence once in a while instead of every insert.

ChssPly76