-->
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.  [ 9 posts ] 
Author Message
 Post subject: mapping a collection to a component ?!
PostPosted: Tue Nov 30, 2004 10:45 am 
Newbie

Joined: Thu Nov 25, 2004 7:54 pm
Posts: 5
Hello there,

I'm trying to come up with an efficient definition and mapping of user authorities. My initial thoughts were of simply having a collection (set maybe) of Strings representing the various rights.

The problem is - I would prefer to map these to columns (of boolena type) in a authorities table, e.g. AUTHORITIES(add_user, add_site, etc. (other rights));

I can't think how this mapping could be possible in Hibernate...?!
Any help or comments would be greatly apprieciated,
Thanks,

Michael D.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 10:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
What should your object model look like?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 11:03 am 
Newbie

Joined: Thu Nov 25, 2004 7:54 pm
Posts: 5
Thanks for the prompt response (apologies for the boolean spelling mistake),

My User object would look like -

public class User...etc.{

// private instance variables for firstName, lastName, etc.
private Set<String> userRights;
...
//getters/setters for the above variables.
...

}

very simple.

I'd just like to be able to map the Set of user rights to columns matching each elements String value.

I am aware of the problems with having no column matching a value in the set (attempts to insert a value into a column that doesn't exist), but I'm happy for this to throw an exception.

Is there any way of achieving this mapping in Hibernate ?

Thanks,

Michael D.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 11:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Have a look at dynamic-component which would give you a Map<String, Boolean> from rolename to boolean. You could probably map a private map as dynamic component and add a public accessor wrapping the map with a Set.

Other possiblitiy:

You could probably create a custom UserType and map it as a normal property ... would rather be a hack and I don't know if it works.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 11:32 am 
Newbie

Joined: Thu Nov 25, 2004 7:54 pm
Posts: 5
Thanks Michael (great name btw),

Reading the (sparse) documentation, in the context of your response, I feel that using dynamic-component is perfect...changing the user rights Set to a Map is completely painless...

Thank you very much,

Michael D.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 11:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
As I find this a quite interesting problem, I'll blog some about the solution I can think of ... so if you give me some minutes, I'll post a link to a more extensive answer :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 11:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ah sorry, it is not that easy ... dynamic-component won't work, expect when you have the user data and permission data in the same table ... for permission data in a different table, you most likely need Hibernate3 features. I will write some more in the blog ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 12:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Look here


Top
 Profile  
 
 Post subject: mapping columns to a map in a class
PostPosted: Tue May 23, 2006 9:15 am 
Newbie

Joined: Tue May 23, 2006 9:05 am
Posts: 5
I have two tables with a one on one relationship. Entity1 will have a map, which contain the values of EntityB. I achieve this map using dynamic-component element.

Is there any way of mapping all the columns in EntityB table to the Entity1 map? Something like,
<dynamic-component>
<property name="*" column="*" />
</dynamic-component>


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