-->
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.  [ 1 post ] 
Author Message
 Post subject: Many to many association using non-primary key columns
PostPosted: Fri Feb 27, 2009 6:52 pm 
Newbie

Joined: Fri Feb 27, 2009 6:42 pm
Posts: 10
Hi guys,

I have two tables -- INSTALL_BUILD_RESULTS and BUILD_RESULTS. IBR has a unique column (non-primary key) called Install_Build_Id and BR has a unique column (non-primary key again) called Build_Id. Both are varchars.

A third table, LINK_BUILD_TO_INSTALL_BUILD is a table simply consisting of the two columns mentioned above, used together as a composite key.

my XMLs for the classes --

BuildResult.hbm.xml --
<hibernate-mapping>
<class name="persistence.BuildResult" table="BUILD_RESULT" schema="dbo" catalog="MSSRELENG_NEWER">
....
<property name="buildId" type="java.lang.String">
<column name="Build_Id" not-null="true" unique="true" />
</property>
....
<set name="installBuildResults" table="LINK_BUILD_TO_INSTALL_BUILD" cascade="all">
<key column="Build_Id" />
<many-to-many column="Install_Build_Id" property-ref="installBuildId" class="persistence.InstallBuildResult" />
</set>
</class>
</hibernate-mapping>

InstallBuildResult.hbm.xml --
<hibernate-mapping>
<class name="persistence.InstallBuildResult" table="INSTALL_BUILD_RESULT" schema="dbo" catalog="MSSRELENG_NEWER">
....
<property name="installBuildId" type="java.lang.String">
<column name="Install_Build_Id" not-null="true" unique="true" />
</property>
....
<set name="buildResults" table="LINK_BUILD_TO_INSTALL_BUILD" cascade="all">
<key column="Install_Build_Id" />
<many-to-many column="Build_Id" property-ref="buildId" class="persistence.BuildResult" />
</set>
</class>
</hibernate-mapping>

and lastly, LinkBuildToInstallBuild.hbm.xml --
<hibernate-mapping>
<class name="persistence.LinkBuildToInstallBuild" table="LINK_BUILD_TO_INSTALL_BUILD" schema="dbo" catalog="MSSRELENG_NEWER">
<composite-id name="id" class="persistence.LinkBuildToInstallBuildId">
<key-many-to-one name="buildResult" class="persistence.BuildResult">
<column name="Build_Id" />
</key-many-to-one>
<key-many-to-one name="installBuildResult" class="persistence.InstallBuildResult">
<column name="Install_Build_Id" />
</key-many-to-one>
</composite-id>
<many-to-one name="buildResult" class="persistence.BuildResult" update="false" insert="false" fetch="select">
<column name="Build_Id" not-null="true" />
</many-to-one>
<many-to-one name="installBuildResult" class="persistence.InstallBuildResult" update="false" insert="false" fetch="select">
<column name="Install_Build_Id" not-null="true" />
</many-to-one>
</class>
</hibernate-mapping>

Simple test code trying to get some results from the db --
LinkBuildToInstallBuildDAO lbtip = new LinkBuildToInstallBuildDAO();
Session hibernateSession = lbtip.getSession();
Criteria crit = hibernateSession.createCriteria(LinkBuildToInstallBuild.class);
crit.list();

errors out with -- >

org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.loader.Loader.doList(Loader.java:2223)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
org.hibernate.loader.Loader.list(Loader.java:2099)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
beans.vijalTests.main(vijalTests.java:14)


Any help would be much appreciated. Using a simple HQL query, "from LinkBuildToInstallBuild" throws an org.hibernate.exception.DataException as well (via MyEclipse Hibernate HQL).

Regards,
Vijal


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.