我做错了什么? Exceprion说我需要制作" id"字段不可插入且不可更新。但我已经有了这些注释。我甚至删除了" id"的setter方法,但它没有效果。缺少什么?
weblogic.application.ModuleException: org.hibernate.MappingException: Repeated column in mapping for entity: com.shop.database.entities.Object column: OBJECT_ID (should be mapped with insert="false" update="false"):org.hibernate.MappingException:Repeated column in mapping for entity: com.shop.database.entities.Object column: OBJECT_ID (should be mapped with insert="false" update="false")
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:696)
at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:718)
at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:740)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:493)
at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
Truncated. see log file for complete stacktrace
My Object.class:
@Entity
@Table(name = "LAB3_OBJECTS")
public class Object {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "OBJECT_ID", length = 10, insertable = false, updatable = false, nullable = false)
private int id;
@Column(name = "NAME")
private String name;
@ManyToOne
@JoinColumn(name = "OBJECT_TYPE_ID", referencedColumnName = "OBJECT_TYPE_ID")
private ObjectType objectType;
@ManyToOne
@JoinColumn(name = "OBJECT_ID")
private Object parent;
public Object() {
}
public Object(String name, ObjectType objectType) {
this.name = name;
this.objectType = objectType;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ObjectType getObjectType() {
return objectType;
}
public void setObjectType(ObjectType objectType) {
this.objectType = objectType;
}
public Object getParent() {
return parent;
}
public void setParent(Object parent) {
this.parent = parent;
}
}
答案 0 :(得分:3)
OBJECT_ID
已用作id列,因此无法用于加入。使用新列
public class MyObject {
...
@ManyToOne
@JoinColumn(name = "PARENT_OBJECT_ID")
private MyObject parent;