-->
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: ManyToMany-Relationship with array
PostPosted: Thu Sep 11, 2008 10:25 am 
Newbie

Joined: Thu Sep 11, 2008 10:19 am
Posts: 6
Hi there,

I try to realize a many-to-many-relationship in my bean. The database is as follows:

Code:
Users {
USR_ID
...
}

Usergroups {
USRGRP_ID
USRGRP_NAME
}

Users_Usergroups {
USR_ID
USRGRP_ID
}


I just want to access a collection of users from a usergroup. So I tried this:

Code:
@ManyToMany
   @JoinTable(
      name="USERS_USERGROUPS",
      joinColumns=@JoinColumn(name="USRGRP_ID"),
      inverseJoinColumns=@JoinColumn(name="USR_ID")
   )
   @IndexColumn(name="USRGRP_ID")
   public User[] getUsers() {
      return users;
   }


Since there is a limitation in the JSF library I use, I can't use a java.util.Set for "users". It has to be an array or a java.util.List. So I had to introduce this @IndexColumn annotation, but I don't know what this annotation is good for.

Has anybody a hint?

Thanks you very much in advance
Newlukai


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2008 10:32 am 
Beginner
Beginner

Joined: Thu Jun 14, 2007 4:33 am
Posts: 39
i think hibernate needs this column because Lists enable you to access elements via an index.

This means the elements have a fixed order. A standard sql-querry doesnt guaranty you that, so an index-column is needed to create.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2008 1:38 am 
Newbie

Joined: Thu Sep 11, 2008 10:19 am
Posts: 6
Thanks. Now I know what this IndexColumn is good for.
But what can I do to avoid creating such a column? For me it doesn't make sense to create a column to serve an implementation issue.
I have a unidirectional many-to-many-relationship and instead of a Set I want to have a List or an Array. This should be possible, shouldn't it?

EDIT: OK. It was my mistake. I switched to java.util.List and it worked. Perhaps the error message that is shown when you use an array without @IndexColumn should be changed? It told me that array/List have to define an @IndexColumn so I didn't try List.


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.