强制休眠插入而不选择语句 [英] Force Hibernate Insert Without Select Statements
问题描述
我正在尝试在表格中插入新记录,我知道在表格之前是独一无二的。我试过调用save()对象,但是做一堆SELECT语句之前做任何INSERT,我不想做,因为我知道对象已经是唯一的。
I am attempting to insert a new record into a table that I know is unique before hand. I have tried calling save() on the object, but that does a bunch of SELECT statements before doing any INSERTs, which I don't want to do because I know the object is already unique.
我为每个事务打开一个新的会话,我可以看到是一个问题,但这是我的域的约束。有没有办法强迫Hibernate在INSERT之前不做任何SELECT?
I am opening a new session for each transaction, which I can see being an issue, but that is a constraint of my domain. Is there some way to force Hibernate to not do any SELECTs before it INSERTs?
推荐答案
您可以使用persist()方法而不是save()。
You can use the persist() method rather than save().
https: //forum.hibernate.org/viewtopic.php?f=1&t=1011405
但是,与save()不同,persist()不会保证标识符值将立即设置在持久化的实例上。
However, unlike save(), persist() does not guarantee that the identifier value will be set immediately on the persisted instance.
https://forum.hibernate.org/viewtopic.php?t=951275
这篇关于强制休眠插入而不选择语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!