-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem with inheritance
PostPosted: Wed Nov 23, 2005 5:24 am 
Newbie

Joined: Mon Jun 06, 2005 11:49 am
Posts: 2
Hi, i am having troubles with the mapping of three classes that has the following hierarchy:

Class A
Class B extends A
Class C extends A

And i have another class D that has a many-to-one asociation to the class A.
The classes A,B and C are mapped using table per subclass strategy and a discriminator column.

I try to call the method "load" from the session with the parameters D.class and the id of the row, and it gives me the right intance of D, but when i try to call the method getA() (expecting an instance of B or C depending on the value of the column) it brings an intance of a proxy that is not a subclass of B or C. Instead it is a subclass of A, so when i try to access a field on the page that belongs to any of the subclasses throws an exception because cannot find that property on the object. I am including the mapping file to see if i am doing something wrong ....

thank you and regards.

J.G.

The many-to-one in class D

<many-to-one name="infractor"
class="es.map.sgtic.sanciones.infractores.dto.Infractor"
cascade="none" outer-join="false" update="true"
insert="true" column="ID_PER_DEPAR_T"/>

Mapping file of class A,B and C:

<?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="es.map.sgtic.sanciones.infractores.dto.Infractor"
table="TBRSNC_INFRACTOR" discriminator-value="null" >
<id name="idInfractor" type="java.lang.Long">
<column name="ID_PER_DEPAR" not-null="true" sql-type="NUMBER"/>
<generator class="sequence">
<param name="sequence">
ID_INFRACTOR_SECUENCE
</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Infractor.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator column="LG_PERSONA" type="string" insert="false"/>
<version name="nuControl" column="NU_CONTROL" type="long"
access="property" unsaved-value="null"/>

<property name="tipoInfractor" type="java.lang.String" update="false"
insert="true">
<column name="LG_PERSONA"/>

</property>
<many-to-one name="departamento"
class="es.map.sgtic.sanciones.departamentos.dto.Departamento"
cascade="none" outer-join="false" update="true"
insert="true" column="ID_DEPSANCION"/>

<set name="expedientes" cascade="none" lazy="true" inverse="true" optimistic-lock="false" table="TBLSNC_EXPESANCION">
<key column="ID_PER_DEPAR_T"/>
<one-to-many class="es.map.sgtic.sanciones.expedientes.dto.Expediente"/>
</set>
<set name="direcciones" cascade="none" lazy="true" inverse="true" optimistic-lock="false" table="TBLSNC_EXPESANCION">
<key column="ID_PER_DEPAR"/>
<one-to-many class="es.map.sgtic.sanciones.direcciones.dto.Direccion"/>
</set>
<set name="documentosI" cascade="none" lazy="true" inverse="true" optimistic-lock="false" table="TBLSNC_EXPESANCION">
<key column="ID_PER_DEPAR"/>
<one-to-many class="es.map.sgtic.sanciones.documentoInicial.dto.DocumentoInicial"/>
</set>
<!--infractor fisico-->
<subclass name="es.map.sgtic.sanciones.infractores.dto.InfractorFisico" discriminator-value="F">
<join table="TBGSNC_INFRAFISICO">
<key not-null="true" update="false" column="ID_PER_DEPAR"/>

<property name="dni" column="DA_DNI"/>

<property name="nif" column="DA_NIF" />


<many-to-one name="nacionalidad"
class="es.map.sgtic.sanciones.nacionalidades.dto.Nacionalidad"
cascade="none" outer-join="false" update="true"
insert="true" column="CD_NACIONAD"/>


</join>
</subclass>

<subclass name="es.map.sgtic.sanciones.infractores.dto.InfractorJuridico" discriminator-value="J">
<join table="TBGSNC_INFRAJURID">
<key not-null="true" update="false" column="ID_PER_DEPAR"/>

<property name="nif" column="DA_NIF"/>

<property name="cif" column="DA_CIF"/>


<many-to-one name="infractorFisico"
class="es.map.sgtic.sanciones.infractores.dto.InfractorFisico"
cascade="none" outer-join="false" lazy="true" fetch="join" update="true"
insert="true" column="ID_PER_DEPAR_T"/>



</join></subclass>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Infractor.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 12:49 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Expose B and C as interfaces- those methods that you need.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 9:38 am 
Newbie

Joined: Sat Nov 19, 2005 10:10 pm
Posts: 9
This is a problem with Proxy and Polymorphism.
You can read about possible solution here:
http://www.hibernate.org/280.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.