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);
}