I’m trying to implement an inherited structure for user types in my application.
@Entity
@Table(name="User_") // Need this since "User" is a reserved name in SQL Server
@Inheritance(strategy=InheritanceType.JOINED)
public class User extends Model {
@Column(nullable=false,unique=true)
public String username;
...
}
@Entity
public class Employee extends User {
...
}
@Entity
public class Client extends User {
...
}
When I do this, the Employee and Client tables that get created do not have any foreign keys to the User_ table, nor does the User_ table have any foreign keys to the Employee or Client tables. How can I make this happen?
Ideally, I’d like an Employee.username column that is a foreign key for User_, so I other tables can have references to Employee.username.
I’m using Play! Framework 1.2.5 and SQL Server 2005.
Answering my own question since it’s been a few days.
The first question I asked was:
This was answered in the comments, thanks axtavt! It turns out that
idis the Primary Key and the Foreign Key.Next up, I wrote this in my question:
And clarified / worded as a question in comments:
I was never able to find an adequate answer to this, so I’m making do with the default (using the numeric id field):
I’ll be happy to accept another answer if this can be solved.