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
|