简体   繁体   中英

hibernate insert into select

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.

Hibernate selects sequence.nextval because it has to return that value back to you (eg set ID on your entity). Unless you're doing something very esoteric I strongly doubt this has a big impact on performance (eg 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.

如果您使用的是Oracle 10客户端或更高版本的客户端,请查看最新的Hibernate版本中的序列标识,以执行所需的操作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM