在没有选择语句的情况下强制休眠插入 [英] Force Hibernate Insert Without Select Statements

查看:19
本文介绍了在没有选择语句的情况下强制休眠插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一条新记录插入到我事先知道是唯一的表中.我曾尝试在对象上调用 save(),但是在执行任何 INSERT 之前会执行一堆 SELECT 语句,我不想​​这样做,因为我知道该对象已经是唯一的.

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 在插入之前不做任何选择?

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?f=1&t=951275

(你可以跳到 christian 在线程中的最后一个帖子)

(and you can jump to christian's last post in the thread)

这篇关于在没有选择语句的情况下强制休眠插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆