0

I have an abstract class AbstractEntity that contains two fields:

  • lastEditTime (LocalDateTime)
  • 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:

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

    @Id
    private String name;

    private String password;

    ...

}

Eclipse shows the following error message:

In implied association override "lastEditUser", join column "lastEditUser_name" cannot be resolved on table "users"

What does it mean? How can I resolve it?

thanks!

  • It's unusual that the abstract mapped superclass is referencing the subclass (in your constructor). This should probably be just the abstract class? – Kevin Hooke Dec 18 '15 at 21:05
  • My intention is to have just one table ("Users"), that contains a column with a Foreign Key to the Primary Key of Users. The column must allow null values. How can I represent that with JPA? My first approach was having the id instead of the object (String instead of UserEntity) .. but the literature says I should reference objects, not IDs. Am I right? – Simon De Uvarow Dec 18 '15 at 21:07
  • The message tells you that there is no lastEditUser_name column in the users table. This is the column which is supposed to contain the foreign key to the user that last edited the User entity instance. – JB Nizet Dec 18 '15 at 21:50
  • If I change "protected UserEntity lastEditUser;" by "protected String lastEditUser;" I get the same error message. So, the problem is not the circular reference. – Simon De Uvarow Dec 18 '15 at 22:03
  • JB Nizet. Should I manually create manually the column in the table? I thought JPA does that. – Simon De Uvarow Dec 18 '15 at 22:06

1 Answers1

0

I disconnected eclipse Datasource. 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.