hi,
i'm having trouble generating the correct onDelete constraints from my annotations. Having 2 Entities with a manyToMany relation: User and Role;
Here's the Annotation in User.java:
Code:
@ManyToMany(targetEntity=com.example.Role.class)
@JoinTable(
name="user_role",
joinColumns=@JoinColumn(name="user_id", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(name="role_id", referencedColumnName="id")
)
@OnDelete(action=OnDeleteAction.CASCADE)
private Set<Role> Roles = new HashSet<Role>();
And the other side, Role.java:
Code:
@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE},
mappedBy="Roles", targetEntity=at.preiserrecords.model.User.class)
@OnDelete(action=OnDeleteAction.CASCADE)
private Set<User> Users = new HashSet<User>();
When exporting the schema to the database using hbm2ddl, the generated sql looks like this:
Code:
create table user (id bigint not null auto_increment, password varchar(255) not null, username varchar(255) not null unique, primary key (id)) type=InnoDB;
create table user_role (user_id bigint not null, role_id bigint not null, primary key (user_id, role_id)) type=InnoDB;
alter table user_role add index FK143BF46AFED144EA (role_id), add constraint FK143BF46AFED144EA foreign key (role_id) references role (id) on delete cascade;
alter table user_role add index FK143BF46AA3FC08CA (user_id), add constraint FK143BF46AA3FC08CA foreign key (user_id) references user (id);// <--- no onDelete cascade created here!
Does anyone know why the onDelete is not generated for the user_id foreign key ?