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.  [ 5 posts ] 
Author Message
 Post subject: how to map 2 identical tables
PostPosted: Fri Jun 17, 2005 11:29 am 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.4

I have this problem. I have 2 identical tables on a database. One of them contains historical information from the other.

I need to query the historcal table so i create anothe hbm and only change the table name.

The problem is that because im using the same domain object hibernate tell me that this object is already imported

Any idea ??

Thanks
Ignacio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 12:19 pm 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
I thinks i can do this with entity-name ... but i cant find any good tutorial on how to use it ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 12:29 pm 
Newbie

Joined: Fri Dec 19, 2003 1:31 pm
Posts: 12
table box1:
idBox number pk
attribute1 varchar(10)
attribute2 varchar(10)

table box2:
idBox number pk
attribute1 varchar(10)
attribute2 varchar(10)

Pojo Box
private int idBox;
private String attribute1;
private String attribute2;

getters and setters... hashCode, equals methods overwritten...

<hibernate-mapping package="domain" auto-import="false">
<class name="Box" table="box1" entity-name="RealBox">
<id column="idBox" name="idBox" type="int">
<generator class="native" />
</id>
<property column="attribute1" name="attribute1" type="string"/>
<property column="attribute1" name="attribute2" type="string"/>
</class>
</hibernate-mapping>


<hibernate-mapping package="domain" auto-import="false">
<class name="Box" table="box2" entity-name="BackupBox">
<id column="idBox" name="idBox" type="int">
<generator class="native" />
</id>
<property column="attribute1" name="attribute1" type="string"/>
<property column="attribute1" name="attribute2" type="string"/>
</class>
</hibernate-mapping>

and then, in your hql secctions, you can differ every one of them, for example "from RealBox as box" and "from BackupBox as box".

hope it works...

_________________
jorge fdz
<< cartago, cr >>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 17, 2005 12:49 pm 
Newbie

Joined: Tue Mar 16, 2004 1:44 pm
Posts: 17
Location: San Jose - Costa Rica
no, it does not work

The following exception was logged org.hibernate.MappingException: duplicate import: CajaLinea

Caja.hbm.xml

<?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="cr.go.ice.vep.domain" auto-import="false">
<class name="Caja" table="CAJA" entity-name="CajaLinea">
<id column="IDCAJA" name="idCaja" type="long" unsaved-value="0">
<generator class="sequence">
<param name="sequence">IDCAJA_SQ</param>
</generator>
</id>
<property column="FECHAAPERTURA" name="fechaApertura" not-null="true" type="timestamp" />
<property column="FECHACIERRE" name="fechaCierre" not-null="false" type="timestamp" />
<property name="nroNotas" insert="false" update="false" formula="(select obtenerNroNotasXCaja(idCaja) from DUAL)" type="long" />
<property name="nroPagos" insert="false" update="false" formula="(select obtenerNroPagosXCaja(idCaja) from DUAL)" type="long" />
<property name="monto" insert="false" update="false" formula="(select obtenerTotalPagosXCaja(idCaja) from DUAL)" type="double" />
<property name="comision" insert="false" update="false" formula="(select obtenerTotalComisionXCaja(idCaja) from DUAL)" type="double" />
<property name="retencionIVA" insert="false" update="false" formula="(select obtenerTotalRetencionIVAXCaja(idCaja) from DUAL)" type="double" />
<property column="ESTADO" name="estado" not-null="true" type="integer" />

<many-to-one class="Recaudador" name="recaudador" not-null="true">
<column name="IDRECAUDADOR" />
</many-to-one>
<set inverse="true" name="notas" cascade="save-update">
<key column="IDCAJA" />
<one-to-many class="Nota" />
</set>
</class>
</hibernate-mapping>

CajaHistorico.hbm.xml

<?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="cr.go.ice.vep.domain" auto-import="false">
<class name="Caja" table="CAJA_HISTORICO" entity-name="CajaHistorico">
<id column="IDCAJA" name="idCaja" type="long" unsaved-value="0">
<generator class="assigned" />
</id>
<property column="FECHAAPERTURA" name="fechaApertura" not-null="true" type="timestamp" />
<property column="FECHACIERRE" name="fechaCierre" not-null="false" type="timestamp" />
<property name="nroNotas" insert="false" update="false" formula="(select obtenerNroNotasXCaja(idCaja) from DUAL)" type="long" />
<property name="nroPagos" insert="false" update="false" formula="(select obtenerNroPagosXCaja(idCaja) from DUAL)" type="long" />
<property name="monto" insert="false" update="false" formula="(select obtenerTotalPagosXCaja(idCaja) from DUAL)" type="double" />
<property name="comision" insert="false" update="false" formula="(select obtenerTotalComisionXCaja(idCaja) from DUAL)" type="double" />
<property name="retencionIVA" insert="false" update="false" formula="(select obtenerTotalRetencionIVAXCaja(idCaja) from DUAL)" type="double" />
<property column="ESTADO" name="estado" not-null="true" type="integer" />

<many-to-one class="Recaudador" name="recaudador" not-null="true">
<column name="IDRECAUDADOR" />
</many-to-one>
<set inverse="true" name="notas" cascade="save-update">
<key column="IDCAJA" />
<one-to-many class="Nota" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: how to map 2 identical tables
PostPosted: Fri Jun 17, 2005 5:31 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
igalmarino wrote:
I need to query the historcal table so i create anothe hbm and only change the table name.




If you are doing read-only queries, you can just map the read-write one, then do SQL native queries into those objects (alias each column).

http://www.hibernate.org/hib_docs/v3/re ... -nativesql

(see second query)

Chris


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