在休眠JPA的getReference()之后不使用setter发出select的情况下无法更新 [英] cannot update without issuing select on using setter after getReference() of hibernate JPA
问题描述
我有以下方法-
@Transactional
public void savethis(){
EntityObject t = entityManagerTreasury.getReference(EntityObject.class, 1);
t.setAction("abc");
}
现在,符合以下答案- https://stackoverflow.com/a/1608621/4881766
Now, going in line with the following answer - https://stackoverflow.com/a/1608621/4881766
我应该只会在我的sql日志中看到一个更新查询.
I should be only seeing an update query in my sql logs.
但是我观察到的行为如下-
However the behaviour i've observed is as follows -
- 提供代码-选择然后更新
- 评论t.setAction("abc");行-没有选择也没有更新
- 用find()替换getReference()-选择然后更新
我期望的行为是,如果我在代理上使用任何getter,则应该发出选择,但是当仅使用setter时,我希望在方法末尾通过更新和更新来提交更改.没有选择发布.
The behaviour i was expecting was that if i use any getter on the proxy, then a select should be issued, but when only using a setter, i wanted the changes to be committed at the end of the method with an update and no select being issued.
结果是,无论我对代理对象,getter或setter做什么,它都会发出选择.
Turns out, no matter what i do with the proxy object, getter or setter, it issues a select.
我想更新给定ID的实体的选定字段. 如果有任何方法可以在不编写jpql或本机查询的情况下更新我想要的任何字段,我将不胜感激.
I want to update selected fields of an entity for a given id. If there is any way to update any fields that i want without writing jpql or native query, I'd really appreciate it.
提前谢谢!