Hi,
I am using annotations to create my DB schema but I have a problem with composite primary keys.
Hibernate generates two columns consisting of the primary key of the first part of the composite and of the second part (User and Role). So far no problem, but Hibernate generates another 2 columns that are handled as foreign keys to User and Role again:
table user_role:
roleid userid user_id role_id
What I prefer is to have only two columns user_id and role_id that on the one hand represent my primary composite key and on the other hand represent foreign keys to user and role.
This is my annotated class:
Code:
@Entity
@Table(name="USER_ROLE")
public class UserRole extends BasicEntity {
// Fields
// Composite Key
@Id
private UserRoleId id;
@ManyToOne
private Role role;
@ManyToOne
private Users users;
// Constructors
/** default constructor */
public UserRole() {
}
// Property accessors
public UserRoleId getId() {
return this.id;
}
public void setId(UserRoleId id) {
this.id = id;
}
public Role getRole() {
return this.role;
}
public void setRole(Role role) {
this.role = role;
}
public Users getUsers() {
return this.users;
}
public void setUsers(Users users) {
this.users = users;
}
}
This is the ant build file with the crucial part:
Code:
<annotationconfiguration configurationfile="${src}/hibernate.cfg.xml"/>
<hbm2ddl drop="true" create="true" outputfilename="DataModel.sql" />
How to generate only role_id and user_id once?