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

查看:116
本文介绍了休眠和无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类,一个Entity和有一个字段; 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天全站免登陆