-->
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: Unique constraint in collection mapping
PostPosted: Wed Sep 19, 2007 4:52 am 
Newbie

Joined: Wed Sep 19, 2007 3:56 am
Posts: 2
Hello.

I have one problem, I can't solve.

So, I have a list of articles, that user has visited:

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@org.hibernate.annotations.CollectionOfElements
@JoinTable(
name = "t_profile_visited_articles",
joinColumns = {@JoinColumn(name = "f_profile_id")},
inverseJoinColumns = {@JoinColumn(name = "f_article_id", unique = false)},
uniqueConstraints = {@UniqueConstraint(columnNames =
{"f_profile_id", "f_article_id", "f_position"})}
)
@org.hibernate.annotations.IndexColumn(name = "f_position")
private List<Article> visitedArticles = new ArrayList<Article>();

Generated SQL:

create table t_profile_visited_articles (
f_profile_id int8 not null,
f_article_id int8 not null,
f_position int4 not null,
primary key (f_profile_id, f_position),
unique (f_profile_id, f_article_id, f_position),
unique (f_article_id)
);

The problem I see is because of "unique (f_article_id)". I tried set up unique=false in JoinCoulmn, but it doesn't work.

Does anyone know how it's possible to prevent creating this unique constraint?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 19, 2007 5:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
That is strange.
Article is an entity right?
So get rid of @org.hibernate.annotations.CollectionOfElements , and see what happens

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 2:53 am 
Newbie

Joined: Wed Sep 19, 2007 3:56 am
Posts: 2
Hello, emmanuel.

Yes, you're right. CollectionOfElements is redundant.
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.