休眠:标识符

发布于 2024-07-14 13:28:27 字数 97 浏览 4 评论 0原文

使用 Hibernate 时:

我必须为每个实体标识一个 id 或复合 id, 如果我想使用没有任何主键且没有复合键的表怎么办...

提前谢谢

When using Hibernate:

Must I identify an id or composite id for each entity,
What about if I want to use table without any primary key and without composite key ...

Thanx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(2

椒妓 2024-07-21 13:28:27

没有键的表不是一个好的关系模型。 我不会推荐它。

Hibernate 的最佳实践表明您应该有一个 id。 复合 id 对于遗留应用程序是可行的,但并不总是最好的主意。

如果你确实必须有一个没有键的表,我建议你不要使用 Hibernate。 它是一个 ORM 工具,听起来您既没有正确考虑对象也没有正确考虑关系表。 从 JDBC 开始。

A table without a key isn't a good relational model. I would not recommend it.

Hibernate's best practices say you should have an id. Composite ids are workable for legacy apps, but not always the best idea.

If you really must have a table without a key, I'd suggest that you shouldn't use Hibernate. It's an ORM tool, and it sounds like you're thinking about neither objects nor relational tables properly. Start with JDBC.

你在看孤独的风景 2024-07-21 13:28:27

如果您正在使用遗留模式,那么您需要查看 复合 ID

I you are working with a legacy schema then you need to have a look at composite-id.

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