Org.Hibernate.AnnotationException:没有为实体指定标识符我没有在我的表中的ID [英] Org.Hibernate.AnnotationException: No Identifier Specified For Entity I don't have a id in my table
本文介绍了Org.Hibernate.AnnotationException:没有为实体指定标识符我没有在我的表中的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用数据库中的表格,并且该表格没有主键或具有可充当主键的唯一值的正确列,我没有权限更改该表。
I'm working with a table in a database and that table don't have a primary key or a proper column whith a unique value who can act as a primary key, I don't have permissions to alter that table.
我该怎么办?我尝试将@id注释放在随机列中,并且它工作正常,但我不知道这会在以后出现什么问题。
What should I do? I tried putting a @id annotation in a random column and it worked, but I don't know if this is going to bring any trouble later on. what can I do?
我的课程
@Entity
@Table(name="my_table")
public class TheTable {
@Column (name="name", nullable=false)
private String name;
@Id <--- I just put this id in this random column but this column should not be a id column
@Column (name="anyfield", nullable=false)
private String anyfield;
}
推荐答案
使用@id的错误导入:
I had this problem and was using the wrong import for @id:
请确保它是:
Make sure it's:
import javax.persistence.Id;
而不是:
and not:
import org.springframework.data.annotation.Id;
这篇关于Org.Hibernate.AnnotationException:没有为实体指定标识符我没有在我的表中的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文