-->
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.  [ 1 post ] 
Author Message
 Post subject: Annotations - Part of primary key marked as unique
PostPosted: Thu Dec 21, 2006 10:20 am 
Newbie

Joined: Tue Dec 05, 2006 10:09 am
Posts: 2
Using Hibernate 3.2 Annotations and DDL to generate table I do I stop one of the primary key from been flagged as unique.


I have a scenario where my users might have more than one role. I have implemented this using JoinTable as shown below

@OneToMany
@JoinTable(name="UserRole",
joinColumns = { @JoinColumn( name="user_id", unique = false) },
inverseJoinColumns = @JoinColumn( name="role_id", unique=false, insertable=false, updatable=false)
)
public Set<Role> getRoles() {
return roles;
}

void setRoles(Set<Role> roles){
this.roles = roles;
}

public void addRole(Role role) {
getRoles().add(role);
}


The generated SQL from the DDL utility are shown below (NOTICE that role_id is flagged as unique)

create table UserRole (
user_id bigint not null,
role_id bigint not null,
primary key (user_id, role_id),
unique (role_id)
) type=InnoDB;

alter table UserRole
add index FKF3F76701F991D007 (user_id),
add constraint FKF3F76701F991D007
foreign key (user_id)
references User (id);

alter table UserRole
add index FKF3F7670154670C27 (role_id),
add constraint FKF3F7670154670C27
foreign key (role_id)
references Role (id);


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

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.