gpt4 book ai didi

java - org.hibernate.MappingException :Repeated column in mapping for entity

转载 作者:行者123 更新时间:2023-12-01 17:25:13 26 4
gpt4 key购买 nike

我有以下实体类和另一个用于复合主键的类

实体类

@Entity
@Table(name = "PROJECTS")
public class Project {
private Integer SlNo;
private Long projectNo;
private Date projectDate;

@EmbeddedId
ProjectPK projectPK;

主键类

public class ProjectPK implements Serializable {

private Integer SlNo;
@Column(name = "project_no", insertable = false, updatable = false)
private Long projectNo;

public ProjectPK(){
}
// with getters and setters and equals and hashCode implementation

问题是我遇到以下异常

:org.hibernate.MappingException:Repeated column in mapping for entity
: test.Project column: projectNo (should be mapped with
insert="false" update="false")

我在Project Entity类中添加了以下内容,但我得到了相同的异常

@Column(name = "project_no", insertable = false, updatable = false)

编辑 1

CriteriaBuilder cb = entityManager.getCriteriaBuilder();

CriteriaQuery<Long> countQ = cb.createQuery(Long.class);
Root<Project> empCount = countQ.from(Project.class);
countQ.select(cb.count(empCount));

TypedQuery<Long> countquery = entityManager.createQuery(countQ);// error in this line

最佳答案

为什么要声明 SlNoprojectNo 字段两次?只需从 Project 类中删除它们就可以了。

或者,更好的是,删除 ProjectPK 类并将 Project 类修改为以下内容(请注意,此方法仅适用于 Hibernate):

@Entity
@Table(name = "PROJECTS")
public class Project implements Serializable {

@Id
private Integer SlNo;

@Id
private Long projectNo;

private Date projectDate;
}

关于java - org.hibernate.MappingException :Repeated column in mapping for entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15475367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com