实体经理管理
实体经理如何管理?
我正在读几篇文章
http://codeidol.com/java/netbeans/Persistence- EntityManager/Interacting-with-an-EntityManager/
我遇到了几个问题要问!
使用后
Customer cust = entityManager.find(Customer.class, 2);
如果我们实际上更改了当前客户 bean 的主 Id,
问题 1: 实体经理仍然知道要管理什么吗?既然是使用主键来查找所有数据?
问题2:如果我们完全改变数据并持久化,也就是 “将其插入数据库的行为”感觉不会相同,原始对象和持久化对象会相同吗?它仍然由实体管理器管理吗?即使一切都会更新?数据库中有两个对象还是一个对象?
只是一些值得深思的东西!
How does an entity manager manage?
I was reading a couple of articles
http://codeidol.com/java/netbeans/Persistence-EntityManager/Interacting-with-an-EntityManager/
I came across a couple of questions to ask!
After using
Customer cust = entityManager.find(Customer.class, 2);
If we in fact change the primary Id of the current customer bean,
Question 1:
Will the Entity Manager still know what to manage? Since it is using a primary key to find all the data?
Question 2: If we completely change the data and persist, which is
"act of inserting it within a database" it feels like it won't be the same, will the original object and the persisted object be the same? Is it still managed by the Entity Manager? Even though everything will get updated? Will there be two objects or one inside the database?
Just some food for thought!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
永远不要更改持久实体的主键值:
- 它不会起作用
- 即使这样做,该主键的所有外键约束无论如何都会被破坏
主键应该是不可变的。
Don't ever change the primary key value of a persistent entity:
- it won't work
- even if it did, all the foreign key constraints to this primary key would break anyway
A primary key is supposed to be immutable.