Hi,
I'm having a problem with warnings of the type
Code:
Narrowing proxy to class org.psygrid.data.model.hibernate.DataSet - this operation breaks ==
appearing in the logs.
First off, I can categorically say that there is no explicit casting in the code! Just thought I['d get that out of the way to start with ;-)
The situation is this. I am using Hibernate as the back-end for a web-service, and as such need to work in a disconnected way. So, for a web-service method to retrieve an object from the database, the relevant object is obtained using Hibernate, then all of its properties are copied (still in the session) to an equivalent DTO bean that can be returned by the web-service method.
OK, so the problem occurs when I am trying to retrieve a single Record object from the database. Within a Hibernate session I retrieve the Record object then calls its toDTO method which constructs the equivalent DTO bean that will be returned by the web-service method. The Record class extends the ElementInstance class (see abridged code snippet below) so calls super.toDTO. Now, each ElementInstance has a reference to an Element object. DataSet extends Element, and in the case of a Record the reference is actually to a DataSet.
Code:
public class Element{
private List<Element> children = new ArrayList<Element>();
public void toDTO(org.psygrid.data.model.dto.Element dtoE, Map<Persistent, org.psygrid.data.model.dto.Persistent> dtoRefs, RetrieveDepth depth){
}
}
public class DataSet extends Element {
public org.psygrid.data.model.dto.DataSet toDTO(Map<Persistent, org.psygrid.data.model.dto.Persistent> dtoRefs, RetrieveDepth depth){
super.toDTO(dtoDS, dtoRefs, depth);
}
}
public class ElementInstance {
private Element element;
private List<ElementInstance> children = new ArrayList<ElementInstance>();
public void toDTO(org.psygrid.data.model.dto.ElementInstance dtoEI, Map<Persistent, org.psygrid.data.model.dto.Persistent> dtoRefs, RetrieveDepth depth){
super.toDTO(dtoEI, dtoRefs, depth);
if ( null != this.element ){
dtoEI.setElement(this.element.toDTO(dtoRefs, depth));
}
}
}
public class Record extends ElementInstance {
public void toDTO(org.psygrid.data.model.dto.Record dtoR, Map<Persistent, org.psygrid.data.model.dto.Persistent> dtoRefs, RetrieveDepth depth){
super.toDTO(dtoR, dtoRefs, depth);
}
}
The warning seems to be caused by the line
Code:
dtoEI.setElement(this.element.toDTO(dtoRefs, depth));
in the ElementInstance class, in the case where the ElementInstance is actually a Record, so the Element is actually a DataSet.
Anybody got any ideas?
cheers, Rob
Hibernate version: 3.1beta3
Mapping documents (partial):Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="t_persistents" name="org.psygrid.data.model.hibernate.Persistent">
<id name="id" column="c_id">
<generator class="native"/>
</id>
<version unsaved-value="undefined" name="version" column="c_version"/>
<joined-subclass name="org.psygrid.data.model.hibernate.Element" table="t_elements">
<key column="c_id"/>
<property name="name" column="c_name"/>
<list cascade="all-delete-orphan" name="children">
<key not-null="false" column="c_parent_id"/>
<list-index column="c_index"/>
<one-to-many class="org.psygrid.data.model.hibernate.Element"/>
</list>
<joined-subclass name="org.psygrid.data.model.hibernate.DataSet" table="t_datasets">
<key column="c_id"/>
<property name="versionNo" column="c_version"/>
<property name="published" column="c_published" not-null="true"/>
</joined-subclass>
</joined-subclass>
<joined-subclass name="org.psygrid.data.model.hibernate.ElementInstance" table="t_elem_insts">
<key column="c_id"/>
<set cascade="all" name="children">
<key not-null="false" column="c_parent_id"/>
<one-to-many class="org.psygrid.data.model.hibernate.ElementInstance"/>
</set>
<many-to-one column="c_element_id" cascade="none" class="org.psygrid.data.model.hibernate.Element" not-null="true" name="element"/>
<many-to-one column="c_record_id" class="org.psygrid.data.model.hibernate.Record" not-null="false" name="record"/>
<joined-subclass name="org.psygrid.data.model.hibernate.Record" table="t_records">
<key column="c_id"/>
<many-to-one unique="true" column="c_identifier_id" cascade="none" class="org.psygrid.data.model.hibernate.Identifier" not-null="true" name="identifier"/>
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>
Name and version of the database you are using:MySQL 4.1.15
Debug level Hibernate log excerpt:Code:
10:20:49,609 DEBUG TwoPhaseLoad:104 - resolving associations for [org.psygrid.data.model.hibernate.DataSet#903]
10:20:49,610 DEBUG CollectionLoadContext:141 - creating collection wrapper:[org.psygrid.data.model.hibernate.Element.children#903]
10:20:49,610 DEBUG DefaultLoadEventListener:153 - loading entity: [org.psygrid.data.model.hibernate.DataSet#903]
10:20:49,611 DEBUG DefaultLoadEventListener:196 - entity proxy found in session cache
10:20:49,613 WARN StatefulPersistenceContext:614 - Narrowing proxy to class org.psygrid.data.model.hibernate.DataSet - this operation breaks ==