-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem in implementing one-to-many association
PostPosted: Fri Apr 21, 2006 2:34 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 3:44 am
Posts: 32
I want to try a one-many association. I have created 2 tables. Table1 and TableMany

Table1 has pk1 as PK

TableMany has pk1 as FK referring to pk1 of Table1
TableMany has PKOFTABLE2 as PK

public class Table1
{


private int intPK=0;
private String column1=null;
private String column2=null;
private Set tableMany = new HashSet();

//get / setter for above

}


public class TableMany
{


private int intPK=0;
private int column4;
Table1 table1;
//get / setter for above

}



TABLE1.hbm.xml

<hibernate-mapping>

<class name="com.sam.common.Table1" table="TABLE1">
<id name="intPK" column="pk1">
<generator class="native" />
</id>


<property name="column1" column="column1" />
<property name="column2" column="column2" />

<set name="tableMany" >
<key column ="pk1" />
<one-to-many class="com.sam.common.TableMany" />
</set>


</class>



</hibernate-mapping>

TABLEMany.hbm.xml


<class name="com.sam.common.TableMany"
table="TABLEMany" >

<id name="intPk" column="PKOFTABLE2" >
<generator class="native" />
</id>

<property name="column4" column="column4" />

<many-to-one
name="table1"
class="com.sam.common.Table1"
column="pk1"
/>



</class>



</hibernate-mapping>

I have included both the files in HibernateCFG....

when I call HQL like , from TableMany I get following error

Error : Association references unmapped class: com.sam.common.TableMany


Help me in getting this working


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 3:08 am 
Newbie

Joined: Wed Oct 19, 2005 7:29 am
Posts: 5
Could it be the CASE issue. You are referencing to class TableMany, where as the name of your mapping is TABLEMany.,hbm.xml
Try changing it to TableMany.hbm.xml & then check.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 3:41 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 3:44 am
Posts: 32
nopes pal, doesnt work.....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 3:58 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 3:44 am
Posts: 32
got both the files to be mapped and when i tried to invoke a hql ,
from TableMany

I got the following exception, cny clue for this

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.sam.common.TestHibernateProxy.<init>(TestHibernateProxy.java:70)
at com.sam.common.TestHibernateProxy.main(TestHibernateProxy.java:127)


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