-->
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: Could not initializa collection on one-to-many association
PostPosted: Thu Sep 08, 2005 7:01 am 
Newbie

Joined: Thu Sep 08, 2005 6:54 am
Posts: 1
Hello,

I'm using Hibernate 2.1.7 with Ms SQL server and have a doubt.

I have a one-to-many association from table A (T_AGENT) to B (T_AGENCY_AGENT). However, it is possible that the key in A is not present in table B, and I'm getting this message:

Hibernate: select agencyagen0_.agentid as agentid__, agencyagen0_.id as id__, ag
encyagen0_.id as id0_, agencyagen0_.agentid as agentid0_, agencyagen0_.agencyid
as agencyid0_ from T_AGENCY_AGENT agencyagen0_ where agencyagen0_.agentid=? orde
r by agencyagen0_.agentid
Hibernate Exceptioncould not initialize collection: [com.xp.dataobject.Agent.age
ncyAgent#2]

the id 2 is not present in table B (T_AGENCY_AGENT).

these are my mappings:

<hibernate-mapping>
<class name="com.xp.dataobject.AgencyAgent" table="T_AGENCY_AGENT">

<id name="agencyAgentId" column="id" type="java.lang.Integer">
<generator class="increment"/>
</id>

<many-to-one name="agent" class="com.xp.dataobject.Agent" column="agentid"/>

</class>
</hibernate-mapping>

and

<hibernate-mapping>
<class name="com.xp.dataobject.Agency" table="T_AGENCY">

<id name="agencyId" column="id" type="java.lang.Integer">
<generator class="increment"/>
</id>

<property name="status" column="StatusID" type="java.lang.Integer"/>
<property name="city" column="city" type="java.lang.String"/>
<property name="zip" column="zipcode" type="java.lang.String"/>

<set name="agencyAgent" table="T_AGENCY_AGENT" inverse="true" cascade="none" order-by="agentid">
<key column="agencyid"/>
<one-to-many class="com.xp.dataobject.AgencyAgent"/>
</set>

</class>
</hibernate-mapping>


what can I do to avoid this problem?

many thanks


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.