Org.Hibernate.AnnotationException: No Identifier Specified For Entity I don#39;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:
确保它是:
import javax.persistence.Id;
而不是:
import org.springframework.data.annotation.Id;
这篇关于Org.Hibernate.AnnotationException:没有为实体指定标识符我的表中没有 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Org.Hibernate.AnnotationException:没有为实体指定标识符我的表中没有 id
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
