-->
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.  [ 2 posts ] 
Author Message
 Post subject: Mapping a composite-element in an entity returns wrong class
PostPosted: Thu Apr 22, 2010 9:31 am 
Newbie

Joined: Tue Jan 06, 2009 5:08 am
Posts: 10
Hi there,
I have a problem mapping a composite-element inside a map correctly in Java.
I have defined an entity using entity-name and inside that, I have a userAccess property that maps a User ID to a composite-element.
The composite-element requires a special class, which is fine, just that a query does not return the class (in this case AccessRightEntry), but a Map.
I am using Hibernate 3.3.
Code:
<class entity-name="MyObject">
   <id name="id" column="ID" length="32" type="string" unsaved-value="null">
      <generator class="uuid" />
   </id>
   <map name="userAccess" table="ACCESS_RIGHTS" lazy="false">
       <key column="OBJECT_ID" />
      <map-key column="USER_ID" type="string" length="32" />
      <composite-element class="AccessRightEntry">
         <property name="right" column="USER_RIGHT" />
         <property name="role" column="USER_ROLE" />
      </composite-element>
      <!-- <element column="USER_RIGHT" type="integer" />  -->
   </map>
</class>


Now in Java:
Code:
List<Map<String,Object>> result = s.createQuery("MyObject").list();
for (Map<String,Object> row : result) {
   AccessRightEntry are = (AccessRightEntry) row.get("userAccess");    // This throws a ClassCastException, since the value in userAccess is a Map
   are.setRight(AccessRightEntry.FULL_ACCESS);
}


Top
 Profile  
 
 Post subject: Re: Mapping a composite-element in an entity returns wrong class
PostPosted: Tue May 11, 2010 7:58 am 
Newbie

Joined: Tue Jan 06, 2009 5:08 am
Posts: 10
Hi again,

I'm still having the same problem. To fix it, I created a conversion function, that maps Map < -- > AccessRightEntry.
What I noticed while doing that, is that the value from the rights field is also present in the role field of the Map, which seems like a very odd behavior.

I'm guessing, that there is still something wrong with my definition, I just cannot see the mistake.
I could really use some hints!

Cheers Torti


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