| Hi Christian, Thanks for your reply. >>To what table should it create a FK to? I supposed that it should create FK to table RegularUser. >>You entity User uses the TABLE_PER_CLASS strategy, so every subclass will have a different table Right. And as I understand every subclass has its own private Long userId property inherited from base class so why hibernate can't just use this property to create FK to it. >>Do you have any other subclasses of User? Yes, I do. I have several subclasses of abstract class User and more over, some of that subclasses also have subclasses. To be more precise I have hierarchy like next
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class User implements Serializable{
}
@Entity
@Table(name = "RegularUsers")
public class RegularUser extends User {
}
@Entity
@Table(name = "Companies")
public class Company extends User {
}
@Entity
@Table(name = "Admins")
public class Admin extends RegularUser {
}
@Entity
@Table(name = "Editors")
public class Editor extends RegularUser {
}
and so on. The strange thing here for me is that I have two other classes with @JoinColumn annotation similar to hierarchy above and in that case all works fine. These are those classes
@Entity
@Table(name = "CompanyDetails")
public class CompanyDetails implements Serializable {
@Id
@Column(name = "CompanyDetailsID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long detailsId;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "CompanyID_FK", referencedColumnName = "UserID")
private Company company;
}
@Entity
@Table(name = "Companies")
public class Company extends User {
}
|