带有 JPA + 循环引用的继承摘要 class
Inherited abstract class with JPA + Circular reference
我有一个包含两个字段的抽象 class AbstractEntity:
- lastEditTime (LocalDateTime)
- lastEditUser(用户实体)
代码如下:
@MappedSuperclass
public abstract class AbstractEntity {
protected LocalDateTime lastEditTime;
protected UserEntity lastEditUser;
protected AbstractEntity () { }
protected AbstractEntity (UserEntity creatorUser) {
lastEditTime = LocalDateTime.now();
lastEditUser = creatorUser;
}
public LocalDateTime getLastEditTime() {
return lastEditTime;
}
public void setLastEditTime(LocalDateTime lastEditTime) {
this.lastEditTime = lastEditTime;
}
public UserEntity getLastEditUser() {
return lastEditUser;
}
public void setLastEditUser(UserEntity lastEditUser) {
this.lastEditUser = lastEditUser;
}
}
然后我有 UserEntity class,它有很多不同的字段:
@Entity
@Table(name = "Users")
public class UserEntity extends AbstractEntity {
@Id
private String name;
private String password;
...
}
Eclipse 显示以下错误消息:
In implied association override "lastEditUser", join column "lastEditUser_name" cannot be resolved on table "users"
这是什么意思?我该如何解决?
谢谢!
我断开了 Eclipse 数据源。然后我清理项目(错误消息消失了),然后我删除了数据库中的 tables,最后我 运行 一个测试用例来重新创建 tables.
新的 table 有两个继承的列。
我有一个包含两个字段的抽象 class AbstractEntity:
- lastEditTime (LocalDateTime)
- lastEditUser(用户实体)
代码如下:
@MappedSuperclass
public abstract class AbstractEntity {
protected LocalDateTime lastEditTime;
protected UserEntity lastEditUser;
protected AbstractEntity () { }
protected AbstractEntity (UserEntity creatorUser) {
lastEditTime = LocalDateTime.now();
lastEditUser = creatorUser;
}
public LocalDateTime getLastEditTime() {
return lastEditTime;
}
public void setLastEditTime(LocalDateTime lastEditTime) {
this.lastEditTime = lastEditTime;
}
public UserEntity getLastEditUser() {
return lastEditUser;
}
public void setLastEditUser(UserEntity lastEditUser) {
this.lastEditUser = lastEditUser;
}
}
然后我有 UserEntity class,它有很多不同的字段:
@Entity
@Table(name = "Users")
public class UserEntity extends AbstractEntity {
@Id
private String name;
private String password;
...
}
Eclipse 显示以下错误消息:
In implied association override "lastEditUser", join column "lastEditUser_name" cannot be resolved on table "users"
这是什么意思?我该如何解决?
谢谢!
我断开了 Eclipse 数据源。然后我清理项目(错误消息消失了),然后我删除了数据库中的 tables,最后我 运行 一个测试用例来重新创建 tables.
新的 table 有两个继承的列。