实体经理管理

发布于 2024-11-29 01:57:45 字数 575 浏览 1 评论 0原文

实体经理如何管理?

我正在读几篇文章
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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2024-12-06 01:57:45

永远不要更改持久实体的主键值:
- 它不会起作用
- 即使这样做,该主键的所有外键约束无论如何都会被破坏

主键应该是不可变的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文