-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: hbm2dll does not generate onDelete for manyToMany relation
PostPosted: Thu Apr 16, 2009 7:47 am 
Newbie

Joined: Wed Mar 11, 2009 1:04 pm
Posts: 9
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 ?


Top
 Profile  
 
 Post subject: Re: hbm2dll does not generate onDelete for manyToMany relation
PostPosted: Tue May 05, 2009 7:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I dont think that were ever implemented for schemacreation.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.