-->
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: Support for objects/db tables with composite ids/keys
PostPosted: Tue Jan 18, 2005 1:23 pm 
Beginner
Beginner

Joined: Wed Dec 08, 2004 9:17 am
Posts: 25
Hi,

I have a problem with lazy loading collections of objects with composite keys.

I have the following 2 mappings:
Code:
<hibernate-mapping schema="dbo" package="de.vodafone.rnp.core.business.persistence.hibernate">
    <class name="WorkspaceImpl" table="funarb" proxy="WorkspaceImpl" lazy="true">
        <id name="id" column="arb_lfdnr" type="integer">
            <generator class="assigned">
            </generator>
        </id>
        <property name="name" type="string" column="arb_name">
        </property>
        <property name="owner" type="string" column="arb_ang_ben">
        </property>
        <property name="creationDate" type="date" column="arb_ang_zeit">
        </property>
        <property name="inconsistent" type="boolean" column="arb_aend_jn">
        </property>
        <property name="comment" type="string" column="arb_kommentar">
        </property>
        <set name="versions" lazy="true" inverse="true">
            <key>
                <column name="arb_lfdnr"/>
            </key>
            <one-to-many class="VersionImpl"/>
        </set>
    </class>
</hibernate-mapping>


and

Code:
<hibernate-mapping schema="dbo" package="de.vodafone.rnp.core.business.persistence.hibernate">
    <class name="VersionImpl" table="funver" proxy="VersionImpl" lazy="true">
        <composite-id>
            <key-property name="versionId"/>
            <key-property name="workspaceId"/>
        </composite-id>
        <property name="versionId" type="integer" column="ver_nr"/>
        <property name="workspaceId" type="integer" column="arb_lfdnr" insert="false" update="false"/>
        <property name="name" type="string" column="ver_name"/>
        <property name="creationDate" type="date" column="ver_ang_zeit"/>
        <property name="inconsistent" type="boolean" column="ver_loesch_jn"/>
        <property name="comment" type="string" column="ver_kommentar"/>

        <set name="cellGroups" lazy="true" inverse="true">
            <key>
                <column name="arb_lfdnr"/>
                <column name="ver_nr"/>
            </key>
            <one-to-many class="CellGroupImpl"/>
        </set>
        <many-to-one name="workspace" class="WorkspaceImpl" column="arb_lfdnr"/>
    </class>
</hibernate-mapping>


I can successively retrieve a WorkspaceImpl object from the database, but when I try to access the associated versions collection and hibernate tries to lazily load the set I get the following exception:

Code:
main 18.01.2005 17:22:46.318 [DEBUG]    net.sf.hibernate.SQL     select versions0_.arb_lfdnr as arb_lfdnr__, versions0_.versionId as versionId__, versions0_.workspaceId as workspac2___, versions0_.versionId as versionId0_, versions0_.workspaceId as workspac2_0_, versions0_.ver_nr as ver_nr0_, versions0_.arb_lfdnr as arb_lfdnr0_, versions0_.ver_name as ver_name0_, versions0_.ver_ang_zeit as ver_ang_6_0_, versions0_.ver_loesch_jn as ver_loes7_0_, versions0_.ver_kommentar as ver_komm8_0_ from dbo.funver versions0_ where versions0_.arb_lfdnr=? 
Hibernate: select versions0_.arb_lfdnr as arb_lfdnr__, versions0_.versionId as versionId__, versions0_.workspaceId as workspac2___, versions0_.versionId as versionId0_, versions0_.workspaceId as workspac2_0_, versions0_.ver_nr as ver_nr0_, versions0_.arb_lfdnr as arb_lfdnr0_, versions0_.ver_name as ver_name0_, versions0_.ver_ang_zeit as ver_ang_6_0_, versions0_.ver_loesch_jn as ver_loes7_0_, versions0_.ver_kommentar as ver_komm8_0_ from dbo.funver versions0_ where versions0_.arb_lfdnr=?
main 18.01.2005 17:22:46.327 [DEBUG]    net.sf.hibernate.impl.BatcherImpl preparing statement 
main 18.01.2005 17:22:46.384 [DEBUG]    net.sf.hibernate.type.IntegerType binding '0' to parameter: 1 
main 18.01.2005 17:22:46.556 [DEBUG]    net.sf.hibernate.util.JDBCExceptionReporter SQL Exception 
com.sybase.jdbc2.jdbc.SybSQLException: Invalid column name 'versionId'.

   at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2884)
   at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:2206)
   at com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
   at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:220)
   at com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:203)
   at com.sybase.jdbc2.jdbc.SybStatement.queryLoop(SybStatement.java:1596)
   at com.sybase.jdbc2.jdbc.SybStatement.executeQuery(SybStatement.java:1581)
   at com.sybase.jdbc2.jdbc.SybPreparedStatement.executeQuery(SybPreparedStatement.java:96)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:990)
   at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:965)
   at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
   at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:288)
   at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3303)
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:195)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)


What in this world am I doing wrong that Hibernate creates an SQL query that contains the two java properties that build the composite key for the VersionImpl objects?

Please, please help!

Thanks a lot in advance.

Regards,

Oliver




Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 20, 2005 10:09 am 
Beginner
Beginner

Joined: Wed Dec 08, 2004 9:17 am
Posts: 25
The mapping for VersionImpl was wrong.
See http://forum.hibernate.org/viewtopic.php?t=938008&highlight= for the correct version.


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.