-->
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.  [ 3 posts ] 
Author Message
 Post subject: OneToMany and JoinTable
PostPosted: Fri Jun 27, 2008 3:28 am 
Newbie

Joined: Wed Jun 25, 2008 12:59 pm
Posts: 9
Location: Belgium
Hibernate version: 3.2.6.ga

Hibernate annotations version: 3.3.1.GA

Name and version of the database you are using: Oracle 10g

Hi,

I have the following @Entity Article class:
Code:
@Entity
public class Article implements Serializable{
...
@OneToMany()
@JoinTable(name = "x_art_intr",
            joinColumns = @JoinColumn(name = "xartintr_art_id"),
            inverseJoinColumns = @JoinColumn(name = "xartintr_intr_id"),
            uniqueConstraints = @UniqueConstraint(columnNames = {"xartintr_art_id", "xartintr_intr_id"}))
@CollectionId(columns = @Column(name = "xartintr_id", nullable = false), type = @Type(type = "long"), generator = "my_seq")
@SequenceGenerator(name = "my_seq", sequenceName = "seq")
public Collection<Interest> getInterests(){
...
}


The hbm2ddl generates the following:
Code:
create table x_art_intr (
   xartintr_art_id number(19,0) not null,
   xartintr_intr_id number(19,0) not null,
   xartintr_id number(19,0) not null,
   primary key (xartintr_id),
   unique (xartintr_art_id, xartintr_intr_id),
   unique (xartintr_intr_id)
);

As you see this will cause problems.
Where does the unique (xartintr_intr_id) come from ?


regards,
Tim


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 02, 2008 5:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

have you tried @ManyToMany instead? Your constraint unique (xartintr_intr_id) comes from the fact that you have a @OneToMany mapping.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 04, 2008 4:49 pm 
Newbie

Joined: Wed Jun 25, 2008 12:59 pm
Posts: 9
Location: Belgium
that worked !

actually I needed a many to many
in my case an article can have many interests
and an interest can have many articles
so ManyToMany

I just based myself on a wrong example :(
thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.