[英]Persistent entity '*******' should have primary key error in @Entity class
When creating an @Entity mapping a table my IDE notifies me: Persistent entity '*******' should have primary key
.创建 @Entity 映射表时,我的 IDE 通知我: Persistent entity '*******' should have primary key
。
But the table in the DB doesn't have an ID (I think it's bad but it's legacy which I've no permissions to fix)但是数据库中的表没有 ID(我认为这很糟糕,但它是我无权修复的遗留问题)
What should I do?我应该怎么办? Will it work if I just omit the ID field?如果我只是省略 ID 字段,它会起作用吗? Or should I make up an ID which is not mapped on the table but satisfy the code?还是我应该编一个没有映射到表格但满足代码的ID?
Every JPA entity must have a primary key.每个 JPA 实体都必须有一个主键。 You can find the documentation here .您可以在此处找到文档。
From the Java Persistence book: Identity and Sequencing: here来自 Java Persistence 书:身份和排序: 这里
If your object does not have an id, but its table does, this is fine.如果您的对象没有 id,但它的表有,这很好。 Make the object an Embeddable object, embeddable objects do not have ids.使对象成为可嵌入对象,可嵌入对象没有 id。 You will need a Entity that contains this Embeddable to persist and query it.您将需要一个包含此 Embeddable 的实体来持久化和查询它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.