Reputation: 584
What am I doing wrong? Exceprion says I need to make "id" field not insertable and not updatable. But I already have those annotations. And I even removed setter method for "id", but it had no effect. Is something missing?
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;
}
}
Upvotes: 1
Views: 120
Reputation: 159754
OBJECT_ID
is already used as the id column so cannot be used for joining. Use a new column
public class MyObject {
...
@ManyToOne
@JoinColumn(name = "PARENT_OBJECT_ID")
private MyObject parent;
Upvotes: 3