简体   繁体   中英

JPA Managed Entity: Is a searched Entity still a Managed Entity

If an entity, which I have with Query.getSingleResult found even a Managed Entity. Can I make changes to it and it must not entityManager.merge or persist () call.

EntityManager em = ...
TypedQuery<User> query = em.createQuery("SELECT u FROM User u WHERE u.email = :userEmail");
query.setParameter("userEmail", "user@test.de");
User user = query.getSingleResult();
// change the user name and email
user.setName("Test1");
user.setEmail("test1@test.de");
// that all???

您已经通过EntityManager提取了它,还没有分离它,因此,是的,它仍然是一个受管实体,您对其所做的任何更改都将被写入数据库。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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