强制休眠插入而不选择语句 [英] Force Hibernate Insert Without Select Statements

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

问题描述

我正在尝试在表格中插入新记录,我知道在表格之前是独一无二的。我试过调用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屋!

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