-->
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 ManyToMany
PostPosted: Sat Oct 18, 2008 10:24 am 
Newbie

Joined: Wed Apr 11, 2007 2:35 pm
Posts: 3
Hi everybody,

so i do have at least 5 hibernate books but...
I have a question about ManyToMany relationships.
Say I have


Code:
@Entity
public abstract class Versionable
{
  private String name
  private String version;
}


@Entity
public class File extends Versionable
{   
  @ManyToMany(mappedBy="files")
  private Liste<Project> fromProjects;
}


@Entity
public class Project extends Versionable
{
  @ManyToMany
  private Liste<File> files;
     
}

How can i express that within the Project.files list
the File.name is unique. So it is not possible that a
Project uses a File.name="Readme.txt" with File.version
="1.1" and a second, with same name but File.version="1.2"

Many thanks in advance

Dietmar


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 18, 2008 1:20 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You can use a Map instead of a List. Use the file name as the map key.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 19, 2008 3:08 am 
Newbie

Joined: Wed Apr 11, 2007 2:35 pm
Posts: 3
Hallo nordborg,

fist of all Thanks nordborg for your answer !
i already thougt about this solution, i do not hundredprocent
know, what hibernate additional does for a Map. But i will
give it a try.
Is there a possibility like an additiona annotation? I think
about an @UniqueConstrain addition.

Many Thanks in advance

Dietmar


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.