休眠且无PK [英] Hibernate and no PK

查看:24
本文介绍了休眠且无PK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建一个不包含主键/Id 的表(来自 JPA 注释的 Hibernate @Entity)?

Is it possible to create a table (from a JPA annotated Hibernate @Entity) that does not contain a primary key / Id?

我知道这不是一个好主意;一个表应该有一个主键.

I know this is not a good idea; a table should have a primary key.

推荐答案

我发现这是不可能的.那些使用遗留系统的人真不幸.

I found that its not possible to do so. So bad luck for those working with legacy systems.

如果您进行逆向工程(从现有 JDBC 连接创建 JPA 注释实体),该表将创建两个 Java 类,一个实体和一个字段;id,以及一个包含关系中所有列的可嵌入 id.

If you reverse engineer (create JPA annotated entities from existing JDBC connection) the table will create two Java classes, one Entity and with one field; id, and one embeddable id containing all the columns from your relation.

这篇关于休眠且无PK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆