Hibernate version: 3.2.
Mapping documents:
Code:
// Map Snippet of AppliedPolicy
<map name="keyValues" table="applied_policy_values" lazy="false" cascade="all">
<key column="applied_policy_id"
foreign-key="appl_values_appl_policy_fk"/>
<map-key-many-to-many
column="policy_simple_value_id"
class="PolicySimpleValue"
foreign-key="appl_values_value_fk"
/>
<element column="value" type="text"></element>
</map>
Code:
<class name="PolicySimpleValue" table="policy_simple_value" proxy="PolicySimpleValue">
<id name="name" type="string" access="field" unsaved-value="null" >
<column name="name" length="50"/>
<generator class="assigned"/>
</id>
<version name="version" column="version" access="field"/>
<property name="description" column="description" type="text"/>
<property name="type" column="value_type" type="string" length="10" access="field"/>
<set name="policies" inverse="true" table="policy_attributes" lazy="true">
<key column="policy_simple_value_id" />
<many-to-many column="policy_id" class="Policy" />
</set>
</class>
ClassesCode:
class AppliedPolicy {
.......
public Map<PolicySimpleValue,String> getValues()
public void setValues(Map<PolicySimpleValue,String> map)()
}
class PolicySimpleValue {
// Assigned Id
// equals and hashCode are implemented using
// this attribute only...
String name;
// Other attributes
String descripcion;
int version;
...........
}
The problem or question
1 - I fetch all PolicySimpleValue objects in a transaction
2 - I fetch one AppliedPolicy with all its nested elements
in another transaction
3 - All transactions closed, no hibernate session opened,
trying to find a key in the map:
Now I am going to try to find PolicySimpleValue with
name "A" in the AppliedPolicy object (of course there is
one with the value "X" associated).
If I use the PolicySimpleValue retrieved in step 1, the value
returned is null although there is a PolicySimpleValue named "A" as
a key int the map.
If I iterate over key-values of the retrieved AppliedPolicy map
I can see a PolicySimpleValue with name "A", if I use this
object as a key to the map I can find the correct value in this
case "X".
I tried a similar case but with a PolicySimpleValue SET, just
asking if the set contains my PolicySimpleValue and it works OK.
Of course I can iterate over the map keys asking for every policy name
and find my value, but I really suppose that is not the idea when using a MAP.
I'm not sure what I'm doing wrong, could anyone please give me some
help.
Thanks in advance
tonio