-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with mapping one-to-one
PostPosted: Mon May 30, 2005 11:18 pm 
When you try to mapping a bidiretional mapping one-to-one always the return is an error. After look the SQL generated by the nhibernate I think that is because when you try to save a class for the first time and it has childs the childs don't are INSERTED, they are UPDATED and with a key = 0. That will always return an error because the PRIMARY KEY can't be NULL.

"SQL update or deletion failed (row not found)"


Top
  
 
 Post subject: Now I am registered
PostPosted: Mon May 30, 2005 11:22 pm 
Newbie

Joined: Mon May 30, 2005 11:20 pm
Posts: 9
Location: Brasil
The problem description is below:

I have 3 tables: Captador, CaptadorFisico and a CaptadorJuridico. The Captador has the primary key and depending of the value of the tipo_pessoa it has a child CaptadorFisico or CaptadorJuridico with the primary key as a foreign key to the Captador.

Ok. When I mapping this entities I put for the Captador:

Code:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
   <class name="SisImob.Database.Captador, SisImob.Database" table="Captador">
      <id name="Id" column="idCaptador">
         <generator class="native">
            <param name="sequence">Captador_idCaptador_seq</param>
         </generator>
      </id>
      <property name="DataRegistro" type="Timestamp" not-null="true" />
      <property name="TipoPessoa" type="Int32" not-null="true" />
      <property name="Ativo" not-null="true" />
      <component name="Local">
         <property name="TelCom" type="Serializable" />
         <property name="TelRes" type="Serializable" />
         <property name="Celular" type="Serializable" />
         <property name="Fax" type="Serializable" />
         <property name="TelDemais" length="255" />
         <property name="Homepage" length="80" />
         <property name="Email" length="60" />
         <property name="Logradouro" length="80" not-null="true" />
         <property name="Lote" length="10" />
         <property name="Quadra" length="10" />
         <property name="Numero" length="10" not-null="true" />
         <property name="Edificio" length="80" />
         <property name="Apartamento" length="10" />
         <property name="Complemento" length="100" />
         <property name="Setor" length="80" not-null="true" />
         <property name="Municipio" length="80" not-null="true" />
         <property name="Estado" length="2" not-null="true" />
         <property name="Referencia" length="255" />
         <property name="Cep" type="Serializable" not-null="true" />
      </component>
      <one-to-one
         property-ref="Parent"
         name="DadosFisicos"
         class="SisImob.Database.CaptadorFisico, SisImob.Database"/>
      <one-to-one
         property-ref="Parent"
         name="DadosJuridicos"
         class="SisImob.Database.CaptadorJuridico, SisImob.Database"/>
   </class>
</hibernate-mapping>


For the others:

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
   <class name="SisImob.Database.CaptadorFisico, SisImob.Database" table="CaptadorFisico">
      <id name="Id" column="idCaptador">
         <generator class="foreign">
            <param name="property">Parent</param>
         </generator>
      </id>
      <property name="Nome" length="80" not-null="true" />
      <property name="Sexo" type="Int32" not-null="true" />
      <property name="Nacionalidade" length="60" not-null="true" />
      <property name="Profissao" length="60" not-null="true" />
      <property name="Cpf" type="Serializable" not-null="true" />
      <property name="Rg" type="Serializable" not-null="true" />
      <property name="EstadoCivil" type="Int32" not-null="true" />
      <one-to-one
         name="Parent"
         cascade="delete"
         class="SisImob.Database.Captador, SisImob.Database"
         constrained="true"/>
   </class>
</hibernate-mapping>

and
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
   <class name="SisImob.Database.CaptadorJuridico, SisImob.Database" table="CaptadorJuridico">
      <id name="Id" column="idCaptador">
         <generator class="foreign">
            <param name="property">Parent</param>
         </generator>
      </id>
      <property name="Razao" length="80" not-null="true"/>
      <property name="Cnpj" type="Serializable" not-null="true" />
      <property name="InscEstadual" length="60"/>
      <property name="InscMunicipal" length="60"/>
      <property name="Responsavel" length="80"/>
      <one-to-one
         name="Parent"
         constrained="true"
         cascade="delete"
         class="SisImob.Database.Captador, SisImob.Database"/>
   </class>
</hibernate-mapping>


At now is good, but if I put the attribute cascade = all for the Captador mapping for the children and later try to save a object Captador it give me errors like if the children don't get the ID of the parent, I guess. So what is wrong? I tryed so many thing like put the attribute property-ref in the Captador mapping and others.

Obs.: I need the mapping to be bidirectional


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.