Oky doky. I just gave hibernate 3 a try and mapped the parent as you can see below. (the loader and sql-insert tags are the interesting ones)
Since the Oracle jdbc driver is flexible enough to execute a select statement where an insert or update should come, this works fine.
But I'm again at a loss with Sybase. It does not accept the select (minus the dual of course). I replaced it with a "no op" update, but then hibernate isn't happy because the returned row count is 0 instead of 1. (see exception stack trace below)
I also tried to map the columns with a formula, but this produced a ClassCastException (see below).
Any ideas about how to map this with h3 for Oracle and Sybase are very welcome!
TIA
Ernst
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="ch.bedag.gba.cap.server.business.model.grundstueck.GebaeudeHist" table="TAR">
<id name="myPk"
type="ch.bedag.gba.cap.server.persistence.hibernate.CapiPkType" access="field">
<column name="FAR01" sql-type="systemId" not-null="true"/>
<column name="FAR03" sql-type="id" not-null="true"/>
<generator class="ch.bedag.gba.cap.server.persistence.hibernate.CapiIdentifierGenerator"/>
</id>
<many-to-one name="myGrundstueck" update="false" insert="false" access="field"
class="ch.bedag.gba.cap.server.business.model.grundstueck.Grundstueck">
<column name="FAR01"/>
<column name="FAR07"/>
</many-to-one>
<property name="myGrundstueckPID" column="FAR07" access="field"></property>
<loader query-ref="loadGrundstueckHist"/>
<sql-insert>select ?, ?, ? from dual -- instead of calling update on TAR</sql-insert>
<sql-update>select ?, ?, ? from dual -- instead of calling update on TAR</sql-update>
<sql-delete>select ?, ?, ? from dual -- instead of calling delete on TAR</sql-delete>
</class>
<sql-query name="loadGrundstueckHist">
<return alias="g" class="ch.bedag.gba.cap.server.business.model.grundstueck.GebaeudeHist"/>
select distinct FAR01 as {g.myPk.systemId},
FAR03 as {g.myPk.id},
FAR07 as {g.myGrundstueckPID}
from TAR
</sql-query>
</hibernate-mapping>
Exception with not machting row count:
Code:
org.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1598)
at org.hibernate.persister.BasicEntityPersister.insert(BasicEntityPersister.java:1878)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:37)
at org.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:1224)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:516)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1191)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at ch.bedag.gba.cap.server.persistence.hibernate.HibernateDAO$HibernateTrx.commit(HibernateDAO.java:156)
at ch.bedag.gba.server.persistence.TransactionManager.commitTransaction(TransactionManager.java:84)
at ch.bedag.gba.cap.server.persistence.hibernate.HibernateHistTestCase.testReferenceToHistorized(HibernateHistTestCase.java:61)
Exception with formula in colum tags:
Code:
java.lang.ClassCastException
at org.hibernate.cfg.Binder.makeIdentifier(Binder.java:1212)
at org.hibernate.cfg.Binder.bindRootClass(Binder.java:465)
at org.hibernate.cfg.Binder.bindRoot(Binder.java:1570)
at org.hibernate.cfg.Configuration.add(Configuration.java:336)
at org.hibernate.cfg.Configuration.addDocument(Configuration.java:325)
at ch.bedag.gba.cap.server.persistence.hibernate.HibernateUtil.<init>(HibernateUtil.java:129)
at ch.bedag.gba.cap.server.persistence.hibernate.HibernateUtil.<init>(HibernateUtil.java:94)
at ch.bedag.gba.cap.server.persistence.hibernate.HibernateUtil$Booter.boot(HibernateUtil.java:270)
at ch.bedag.gba.common.bootstrap.BootLevel.boot(BootLevel.java:107)
at ch.bedag.gba.common.bootstrap.BootLevel.boot(BootLevel.java:102)
at ch.bedag.gba.common.bootstrap.AppBootstrap.boot(AppBootstrap.java:49)
at ch.bedag.gba.cap.server.application.CapiServerBootStrap.bootAll(CapiServerBootStrap.java:60)
at ch.bedag.gba.cap.server.application.CapiServer.main(CapiServer.java:31)