java - org.Hibernate.AnnotationException : No Identifier Specified For Entity I don't have a id in my table

标签 java hibernate spring-mvc jpa spring-data

我正在使用数据库中的一个表,并且该表没有主键或具有可以充当主键的唯一值的正确列,我无权更改该表。

我该怎么办?我尝试将@id 注释放在一个随机列中并且它有效,但我不知道这是否会在以后带来任何麻烦。我该怎么办?

我的类(class)

@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 使用了错误的导入:

确保它是:

import javax.persistence.Id;

而不是:

import org.springframework.data.annotation.Id;

关于java - org.Hibernate.AnnotationException : No Identifier Specified For Entity I don't have a id in my table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25851029/

相关文章:

java - Spring - "context:property-placeholder"- 属性优先级

java - 确定列表大小的最快方法

java - 从 SQLQuery 结果中的 id 列获取 Hibernate Entity 实例

hibernate - 运行时异常 :Use of @OneToMany or @ManyToMany targeting an unmapped class

java - Java 中的 ALT 代码

java - Spring Boot @DataJpaTest 不生成 ddl

java - 为每个 Controller 中的每个操作设置模型属性

java - @RequestParam 与 @PathVariable

java - Spring 显示用户刚刚上传的图片,无需重启服务器

java - 如何动态复制另一个不可编辑的 JTextField 中的 JTextField 内容