-->
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: mapped collection is always empty
PostPosted: Sat Mar 21, 2009 10:05 am 
Newbie

Joined: Thu Sep 22, 2005 5:17 pm
Posts: 11
Hello,
I have problem with collection mapping in Hibernate 3.3.1.GA.

I have two database tables: user(id:number, username:varchar2, pass:varchar2) and userpermission(user_id:number, permission:varchar2).

In my application I have entity User with property Set<String> permissions;

It is mapped with
<set name="permissions" table="USERPERMISSION" lazy="false" fetch="join" inverse="false" cascade="all">
<key column="USER_ID" not-null="true"/>
<element column="PERMISSION" type="string" length="40"
not-null="true"/>
</set>

The set of permissions is always empty although it shouldn't. But hibernate user type's nullSafeGet is called and the resultset contains correct data, but the PersistentSet doesn't.

CAn you advice me?
Thanks
blaf

_________________
thanks
blaf


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 4:23 pm 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
What make a row unique in your permission table?

This will probably be a lot easier if you put a synthetic key in your child table.

If you have to keep the child table as you've said, then I think you'll need to declare the userid + permission as the key (compound key), since from relational point of view thats what makes it unique.

Probably would be a good idea to show the .java for your child entity (permission)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 21, 2009 6:05 pm 
Newbie

Joined: Thu Sep 22, 2005 5:17 pm
Posts: 11
There's no permission table in database and no Permission neither UserPermission entity in application. The idea is that there's no need to have permission table in db because it would contain static data without ability to change it, so the data will be stored in resource bundles on application level. In database will be only stored codes of permission.

I think I could create UserPermission entity (and map it) and the collection map with <one-to-many/> instead <element/> but I don't need UserPermission entity in application. I thought <element/> element is intended for situations like this, isn't it?

_________________
thanks
blaf


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.