Hallo zusammen,
eine Klasse A beinhaltet eine java.util.List von Elementen der Klasse B. B ist abstrakt und wird implementiert in B1, B2 und B3. Die Mappings lasse ich durch xdoclet erzeugen.
Code:
public class A {
...
/**
* @return Returns the list of elements.
*
* @hibernate.list
* table="a_elements"
* lazy="false"
* cascade="all"
* @hibernate.collection-key
* column="a_id"
* @hibernate.collection-index
* column="ord"
* @hibernate.collection-many-to-many
* column="elem_id"
* class="B"
*/
public java.util.List getElements() {}
}
/**
* @hibernate.class table="elements"
*/
public abstract class B {
...
}
/**
* @hibernate.joined-subclass table="elem_B1"
* @hibernate.joined-subclass-key column="id"
*/
public class B1 extends B {
...
}
Mein Problem ist jetzt, dass Aufrufe an Elemente der Liste von A.getElements() Instanzen ergeben, die sich so darstellen:
Quote:
obj.toString(): B1@nnnnnn
obj.getClass().getName(): B$$EnhancerByCGLIB$$nnnnnnnn
Da diese Objekte aus Sicht der Reflection-API Instanzen von B sind, finden Bibliotheken wie Velocity die Methoden nicht, die in B1, B2 B3 implementiert werden. Früher (hibernate 2.1.n) hat das immer funktioniert. Was muss ich anders machen? Mit Dank und Gruß,
- Christian
Hibernate version: 3.1 (production)
Mapping documents:Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="A"
table="A"
>
<id
name="id"
column="id"
type="long"
unsaved-value="0"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Poll.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<list
name="elements"
table="A_elements"
lazy="false"
cascade="all"
>
<key
column="A_id"
>
</key>
<index
column="ord"
/>
<many-to-many
class="B"
column="elem_id"
outer-join="auto"
/>
</list>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="B"
table="elements"
>
<id
name="id"
column="id"
type="long"
unsaved-value="0"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-PollElement.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<many-to-one
name="A"
class="xyz"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="A_id"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PollElement.xml
containing the additional properties and place it in your merge dir.
-->
<joined-subclass
name="B1"
table="elem_B1"
>
<key
column="id"
/>
<property
name="value"
type="java.lang.String"
update="true"
insert="true"
column="value"
/>
<property
name="textType"
type="int"
update="true"
insert="true"
column="textType"
/>
</joined-subclass>
<joined-subclass
name="B2"
table="elem_B2"
>
<key
column="id"
/>
<list
name="columns"
table="question_columns"
lazy="true"
cascade="all"
>
<key
column="question_id"
>
</key>
<index
column="ord"
/>
<many-to-many
class="xyz"
column="col_id"
outer-join="auto"
/>
</list>
<property
name="qid"
type="java.lang.String"
update="true"
insert="true"
column="qid"
not-null="true"
/>
<property
name="text"
type="java.lang.String"
update="true"
insert="true"
column="text"
/>
<property
name="state"
type="int"
update="true"
insert="true"
column="state"
/>
</joined-subclass>
</class>
</hibernate-mapping>