简体   繁体   English

具有JPA +循环引用的继承的抽象类

[英]Inherited abstract class with JPA + Circular reference

I have an abstract class AbstractEntity that contains two fields: 我有一个抽象类AbstractEntity,其中包含两个字段:

  • lastEditTime (LocalDateTime) lastEditTime(LocalDateTime)
  • lastEditUser (UserEntity) lastEditUser(UserEntity)

Below is the code: 下面是代码:

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

Then I have the UserEntity class that has many different fields: 然后,我有了UserEntity类,它具有许多不同的字段:

@Entity
@Table(name = "Users")
public class UserEntity extends AbstractEntity {

    @Id
    private String name;

    private String password;

    ...

}

Eclipse shows the following error message: Eclipse显示以下错误消息:

In implied association override "lastEditUser", join column "lastEditUser_name" cannot be resolved on table "users" 在隐式关联覆盖“ lastEditUser”中,无法在表“ users”上解析联接列“ lastEditUser_name”

What does it mean? 这是什么意思? How can I resolve it? 我该如何解决?

thanks! 谢谢!

I disconnected eclipse Datasource. 我断开了Eclipse数据源的连接。 Then I clean the project (the error messages were gone), then I deleted the tables in the database, and finally I run a test case to recreate the tables. 然后,我清理项目(错误消息消失了),然后删除数据库中的表,最后运行测试用例以重新创建表。

The new table has the two inherited columns. 新表具有两个继承的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM