简体   繁体   English

Glassfish / Hibernate保存,无需显式保存

[英]Glassfish/Hibernate save without calling save explicitely

I am using Glassfish 2 and container managed persistence with Hibernate 3.2 as persistence provider. 我使用Glassfish 2和容器管理持久性与Hibernate 3.2作为持久性提供程序。 I have some finder method in my business logic, which manipulates some persistent entities, which have been fetched via the EntityManager . 我的业务逻辑中有一些finder方法,它操纵一些持久化实体,这些实体已经通过EntityManager获取。 The manipulation is just changing a String property (deleting an element from a collection leads to the same effect). 操作只是更改String属性(从集合中删除元素会产生相同的效果)。
I do not call anything like save or persist on my EntityManager . 我不会在我的EntityManager上调用类似保存持久的内容。 I just want to return some changed entities to my client. 我只想将一些更改的实体返回给我的客户端。

It seems when the container commits the transaction the changes to my entity are saved automatically. 当容器提交事务时,似乎会自动保存对我的实体的更改。 Is there some magic Hibernate or Glassfish behaviour I missed completely so far? 到目前为止,我是否完全错过了一些神奇的Hibernate或Glassfish行为?

If the entity you've fetched is in Managed state then at the end of transaction, changes made to the entity will be persisted. 如果您获取的实体处于Managed状态,则在事务结束时,将保留对该实体所做的更改。 That's the contract that the JPA provider must obey to. 这是JPA提供商必须遵守的合同。

This question might be helpful for you: Transactional saves without calling update method 这个问题可能对您有所帮助: 事务性保存而不调用更新方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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