gpt4 book ai didi

java - org.hibernate.MappingException 似乎无缘无故发生

转载 作者:行者123 更新时间:2023-11-29 04:30:31 25 4
gpt4 key购买 nike

我做错了什么? 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

我的对象类:

@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;
}

最佳答案

OBJECT_ID 已用作 id 列,因此不能用于连接。使用新列

public class MyObject {
...
@ManyToOne
@JoinColumn(name = "PARENT_OBJECT_ID")
private MyObject parent;

关于java - org.hibernate.MappingException 似乎无缘无故发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43968410/

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