我有以下实体类和另一类为复合主键org.hibernate.MappingException:在映射重复列实体
实体类
@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
我认为你必须让SlNo只读。你仍然可以在你的代码中阅读它,但你必须使用ProjectPK对象来更新它... – 2013-03-18 11:13:30
@PierreHenry我已经试过SlNo只读,就像projectNo一样,但是这并没有解决问题。 – user75ponic 2013-03-18 12:41:33