Hi,
For days I'm trying to map a class that extends and implements.
The problem is that when an instance of PrestadorPessoaFisica is persisted, data is inserted in table PESSOA but nothing is inserted in table PRESTADOR, and I really need all these classes mapped since there are other persisted classes that references them.
I'm a little desperate, would really appreciate some help.
Thanks in advance,
Thiago Souza
Hibernate version:
2.1.6
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"ftp://localhost/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="empresajunior.business.domain.Pessoa"
table="PESSOA"
dynamic-update="true"
dynamic-insert="true"
select-before-update="false"
optimistic-lock="version"
discriminator-value="P"
>
<id
name="oid"
column="oid_pessoa"
type="java.lang.String"
length="32"
>
<generator class="uuid.hex">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Pessoa.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="subclass"
length="3"
/>
<property
name="nome"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_nome"
length="40"
/>
<component
name="endereco"
class="empresajunior.business.domain.Endereco"
>
<property
name="bairro"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_endereco_bairro"
length="40"
/>
<property
name="cep"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_endereco_cep"
length="9"
/>
<property
name="cidade"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_endereco_cidade"
length="40"
/>
<property
name="complemento"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_endereco_complemento"
length="15"
/>
<many-to-one
name="estado"
class="empresajunior.business.domain.Estado"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="oid_endereco_estado"
/>
<property
name="logradouro"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_endereco_logradouro"
length="50"
/>
<property
name="numero"
type="java.lang.Integer"
update="true"
insert="true"
access="property"
column="int_endereco_numero"
/>
</component>
<set
name="email"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<one-to-many
class="empresajunior.business.domain.Email"
/>
</set>
<set
name="telefone"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<one-to-many
class="empresajunior.business.domain.Telefone"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Pessoa.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="empresajunior.business.domain.PessoaJuridica"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PJ"
>
<property
name="cnpj"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_cnpj"
length="18"
/>
<property
name="inscricaoEstadual"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_inscricao_estadual"
length="12"
/>
<property
name="inscricaoMunicipal"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_inscricao_municipal"
length="10"
/>
<property
name="razaoSocial"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_razao_social"
length="80"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PessoaJuridica.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="empresajunior.business.domain.PrestadorPessoaJuridica"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PPJ"
>
<set
name="habilitacao"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<one-to-many
class="empresajunior.business.domain.Habilitacao"
/>
</set>
<set
name="tipoVinculo"
table="VINCULACAO"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<many-to-many
class="empresajunior.business.domain.TipoVinculo"
column="oid_tipo_vinculo"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PrestadorPessoaJuridica.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</subclass>
<subclass
name="empresajunior.business.domain.PessoaFisica"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PF"
>
<property
name="CPF"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_cpf"
length="12"
/>
<property
name="dataNascimento"
type="java.sql.Date"
update="true"
insert="true"
access="property"
column="date_nascimento"
/>
<component
name="RG"
class="empresajunior.business.domain.RG"
>
<property
name="numero"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_rg_numero"
length="11"
/>
<property
name="orgaoEmissor"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_orgao_emissor"
length="15"
/>
</component>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PessoaFisica.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="empresajunior.business.domain.PrestadorPessoaFisica"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="PPF"
>
<set
name="habilitacao"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<one-to-many
class="empresajunior.business.domain.Habilitacao"
/>
</set>
<set
name="tipoVinculo"
table="VINCULACAO"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<many-to-many
class="empresajunior.business.domain.TipoVinculo"
column="oid_tipo_vinculo"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-PrestadorPessoaFisica.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="empresajunior.business.domain.Membro"
dynamic-update="true"
dynamic-insert="true"
discriminator-value="M"
>
<property
name="cracha"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="str_cracha"
length="10"
/>
<many-to-one
name="cursoPUC"
class="empresajunior.business.domain.CursoPUC"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="oid_curso"
/>
<property
name="previsaoDesligamentoEmpresa"
type="date"
update="true"
insert="true"
access="property"
column="date_previsao_desligamento_empresa"
/>
<property
name="previsaoTerminoCurso"
type="date"
update="true"
insert="true"
access="property"
column="date_previsao_termino_curso"
/>
<set
name="ocupacao"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="oid_membro"
>
</key>
<one-to-many
class="empresajunior.business.domain.Ocupacao"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Membro.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</subclass>
</subclass>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"ftp://localhost/hibernate-mapping-2.0.dtd">
<hibernate-mapping
auto-import="false"
>
<class
name="empresajunior.business.domain.Prestador"
table="PRESTADOR"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id
name="oid"
column="oid_pessoa"
type="java.lang.String"
length="32"
>
<generator class="uuid.hex">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Prestador.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<set
name="habilitacao"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<one-to-many
class="empresajunior.business.domain.Habilitacao"
/>
</set>
<set
name="tipoVinculo"
table="VINCULACAO"
lazy="false"
inverse="false"
cascade="none"
sort="unsorted"
>
<key
column="oid_pessoa"
>
</key>
<many-to-many
class="empresajunior.business.domain.TipoVinculo"
column="oid_tipo_vinculo"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Prestador.xml
containing the additional properties and place it in your merge dir.
-->
<joined-subclass
name="empresajunior.business.domain.PrestadorPessoaFisica"
table="PESSOA">
<key
column="oid_pessoa"
>
</key>
</joined-subclass>
<joined-subclass
name="empresajunior.business.domain.PrestadorPessoaJuridica"
table="PESSOA">
<key
column="oid_pessoa"
>
</key>
</joined-subclass>
</class>
</hibernate-mapping>
Name and version of the database you are using:
MySQL 4