-->
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: ONE-TO-ONE MAPPING AND foreign GENERATOR
PostPosted: Sat Nov 26, 2005 10:16 am 
Newbie

Joined: Sat Nov 26, 2005 10:09 am
Posts: 1
Hello, I`m new to hibernate and now i`m trying to make a one-to-one mapping. The following are the .hbm.xml codes. Why am I gatting this:
org.hibernate.MappingException: could not instantiate id generator

Parent Class:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.matera.bmf.entity">
<class name="Calendario" table="BF_CALENDARIO">



<id name="idCalendario" column="ID_CALENDARIO" type="long">
<generator class="foreign">
<param name="property">calendarioOuro</param>
</generator>
</id>



<property name="serie" column="SERIE"/>
<property name="quantidadePadrao" column="QTD_PADRAO"/>
<property name="dataVencimento" column="DT_VCTO"/>
<property name="precoExercicio" column="VLR_PRECO_EXERCICIO"/>
<property name="taxaRegistro" column="TAXA_REGISTRO"/>
<property name="emolNormal" column="VLR_EMOL_NORMAL"/>
<property name="emolDaytrade" column="VLR_EMOL_DAYTRADE"/>
<property name="funGaranNormal" column="VLR_FUN_GARAN_NORMAL"/>
<property name="funGaranDaytrade" column="VLR_FUN_GARAN_DAYTRADE"/>
<property name="margemNormal" column="VLR_MARGEM_NORMAL"/>
<property name="margemHedger" column="VLR_MARGEM_HEDGER"/>
<property name="mercAgrMesPresente" column="DT_MERC_AGR_MES_PRESENTE"/>
<property name="mercAgrAvisoEntrega" column="DT_MERC_AGR_AVISO_ENTREGA"/>
<property name="corTermMesPresente" column="DT_COR_TERMO_MES_PRESENTE"/>
<property name="corTermAvisoEntrega" column="DT_COR_TERMO_AVISO_ENTREGA"/>

<many-to-one name="mercadoria"
column="ID_MERCADORIA"
class="Mercadoria"
cascade="all"
lazy="false"/>
<one-to-one name="calendarioFuturo"

class="CalendarioFuturo"
cascade="all"
lazy="false"/>
<one-to-one name="calendarioTermo"

class="CalendarioTermo"
cascade="all"
lazy="false"/>
<one-to-one name="calendarioOpcao"

class="CalendarioOpcao"
cascade="all"
lazy="false"/>
<one-to-one name="calendarioOuro"
constrained="true"
class="CalendarioOuro"
cascade="all"
lazy="false"/>

<many-to-one lazy="false" name="tipoOpcao" cascade="save-update"
column="ID_TIPO_OPCAO_CALENDARIO"
class="TipoOpcao"
unique="true" />
</class>
</hibernate-mapping>



Now the Child Class mapping:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.matera.bmf.entity">
<class name="CalendarioOuro" table="BF_CALENDARIO_OURO">
<id name="idCalendario" column="ID_CALENDARIO" type="long">
<generator class="foreign"/>
</id>
<property name="valorAnterior" column="VLR_ANTERIOR"/>
<property name="valorAtual" column="VLR_ATUAL"/>
<property name="valorUltimo" column="VLR_ULTIMO"/>
<property name="valorMaximo" column="VLR_MAXIMO"/>
<one-to-one name="calendario"
class="Calendario"
cascade="all"
lazy="false"/>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 27, 2005 7:15 pm 
Regular
Regular

Joined: Wed May 05, 2004 3:41 pm
Posts: 118
Location: New Jersey,USA
The CalendarioOuro class must have a "non-foreign" id generator. In your case you have both your id generators as foreign which is not possible. What id-generator = foreign means is that the id will be dertived from the primary key of a one-to-one association.

In your case case try:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.matera.bmf.entity">
<class name="Calendario" table="BF_CALENDARIO">
<id name="idCalendario" column="ID_CALENDARIO" type="long">
<generator class="assgined">
</generator>
</id>


What this means is that the "id" for Calendario should be assigned by the Persisting class (i.e. before calling "saveXXX" methods).

Hope that helps.


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.