Hello,
I am using the below hibernate mapping, which defines a map, "widgetMapping". Using this mapping the data is properly persisted, but when it is retrieved and I try to get the ID of the SourceWidget, it returns null, even though the ID is indeed set. Under the debugger I was able to see that calling getId() did not hit the proxy object, but rather went directly to the domain object. When I called getName() it hit the proxy object and properly returned the name. Also, calling getId() on the value (TargetWidget) properly returns the ID. Any indication to what the issue is would be greatly appreciated.
Thanks in advance,
Ryan
hibernate mapping:Code:
<class
name="AbstractThing"
table="Thing" abstract="true" lazy="true">
<id name="id" column="Id" type="string">
<generator class="assigned" />
</id>
<discriminator column="Type" type="string" />
<property name="type" column="Type" type="string"
insert="false" update="false" />
<property name="targetId" column="TargetId" type="string" />
<subclass
name="Thing1"
discriminator-value="Thing1">
<map name="widgetMapping" table="WidgetMapping" lazy="true">
<key column="AbstractThingId" not-null="true" />
<index-many-to-many column="SourceWidgetId"
class="Widget" />
<many-to-many column="TargetWidgetId"
class="Widget" />
</map>
</subclass>
</class>
relevant classes:Code:
public class Thing1 extends AbstractThing {
private Map<Widget, Widget> _widgetMapping;
public Map<Widget, Widget> getWidgetMapping() {
return _widgetMapping;
}
public void setWidgetMapping(Map<Widget, Widget> widgetMapping_) {
_widgetMapping = widgetMapping_;
}
}
public class Widget {
protected Serializable _id;
protected String _name;
public final Serializable getId() {
return _id;
}
public final void setId(Serializable id_) {
_id = id_;
}
public String getName() {
return _name;
}
public void setName(String name_) {
_name = name_;
}
}
usage code:Code:
for (Widget sourceWidget : thing.getWidgetMapping().keySet()) {
System.out.println(sourceWidget.getId()); // null and doesn't hit proxy object
System.out.println(sourceWidget.getName()); // as expected
}
variable inspection:Code:
sourceWidget Widget$$EnhancerByCGLIB$$d5b4abba (id=162)
_id null
_name null
_type null
CGLIB$BOUND true
CGLIB$CALLBACK_0 CGLIBLazyInitializer (id=181)
componentIdType null
constructed true
entityName "Widget"
getIdentifierMethod Method (id=185)
id "cad5f6f76598444c8623d09e6df8283e"
initialized true
interfaces Class<T>[1] (id=187)
overridesEquals true
persistentClass Class<T> (Widget) (id=124)
replacement null
session null
setIdentifierMethod Method (id=192)
target Widget (id=193)
_id "cad5f6f76598444c8623d09e6df8283e"
_name "FooBar"
unwrap false
CGLIB$CALLBACK_1 null
CGLIB$CONSTRUCTED true