-->
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: Illegal attempt to associate a collection with two open sess
PostPosted: Mon Feb 07, 2005 3:34 pm 
Beginner
Beginner

Joined: Mon Dec 08, 2003 12:15 am
Posts: 47
First let me preface this post by saying that I am aware that Hibernate is not the suggested tool for what we are trying to accomplish. Having said that, here's our issue:

I am loading an object graph from an DB2/AS400 database and reconstructing that graph so that we can then save that graph of objects to Oracle 10g. The relations are as follow:

A policy has many units. This is modeled as a one to many parent/child relationship in the mapping file for the AS400. The same for the Oracle mapping files. So in our code we load the object from the AS400 - Look at code below

I keep on getting a net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions and I don't understand how this can be since the object I am trying to save and its children are transient.

Hibernate version: 2.18

Mapping documents:

ORACLE MAPPING DOCS

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.uaig.migration.history.oracle10g.vo.OraPolicyDetails"
table="policy_details"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="policyDetailsKey"
column="POL_DETAILS_ID"
type="java.lang.Integer"
>
<generator class="sequence">
<param name="sequence">POLICYDETAILS_SEQ</param>
</generator>
</id>

<property
name="companyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="COMP_NUMBER"
/>

<property
name="policyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="POL_NUMBER"
/>

<property
name="policyPrefix"
type="java.lang.String"
update="true"
insert="true"
column="POL_PREFIX"
/>

<property
name="clientId"
type="java.lang.String"
update="true"
insert="true"
column="CLIENT_ID"
length="12"
/>

<property
name="generalAgent"
type="java.lang.String"
update="true"
insert="true"
column="GENERAL_AGENT"
length="3"
/>

<property
name="subAgent"
type="java.lang.String"
update="true"
insert="true"
column="SUB_AGENT"
length="6"
/>

<property
name="producingAgent"
type="java.lang.String"
update="true"
insert="true"
column="PRODUCING_AGENT"
length="9"
/>

<property
name="termEffectiveDate"
type="java.util.Date"
update="true"
insert="true"
column="TERM_EFF_DATE"
length="7"
/>

<property
name="termExpDate"
type="java.util.Date"
update="true"
insert="true"
column="TERM_EXP_DATE"
length="7"
/>

<property
name="accoutingDate"
type="java.util.Date"
update="true"
insert="true"
column="ACCOUNTING_DATE"
length="7"
/>

<property
name="entryDate"
type="java.util.Date"
update="true"
insert="true"
column="ENTRY_DATE"
length="7"
/>

<property
name="policyTerm"
type="java.lang.Integer"
update="true"
insert="true"
column="POLICY_TERM"
length="3"
/>

<property
name="policyPayPlan"
type="java.lang.String"
update="true"
insert="true"
column="PAY_PLAN"
length="4"
/>

<property
name="policyState"
type="java.lang.String"
update="true"
insert="true"
column="STATE"
length="2"
/>

<property
name="policyStatus"
type="java.lang.String"
update="true"
insert="true"
column="POLICY_STATUS"
length="1"
/>

<property
name="policyActivity"
type="java.lang.String"
update="true"
insert="true"
column="ACTIVITY"
length="1"
/>

<property
name="policyType"
type="java.lang.String"
update="true"
insert="true"
column="POLICY_TYPE"
length="2"
/>

<property
name="bindingNumber"
type="java.lang.String"
update="true"
insert="true"
column="BINDING_NO"
length="7"
/>

<property
name="quotedPremium"
type="java.math.BigDecimal"
update="true"
insert="true"
column="QUOTED_PREMIUM"
length="11"
/>

<property
name="lastPremium"
type="java.math.BigDecimal"
update="true"
insert="true"
column="LAST_PREMIUM"
length="11"
/>

<property
name="writtenPremium"
type="java.math.BigDecimal"
update="true"
insert="true"
column="WRITTEN_PREMIUM"
length="11"
/>

<property
name="policyFee"
type="java.math.BigDecimal"
update="true"
insert="true"
column="POLICY_FEE"
length="11"
/>

<property
name="nonRenewalRes"
type="java.lang.Integer"
update="true"
insert="true"
column="NON_RENEWAL_RES"
length="2"
/>

<property
name="renewalInd"
type="java.lang.String"
update="true"
insert="true"
column="RENEWAL_IND"
length="1"
/>

<property
name="renewalDiscount"
type="java.lang.String"
update="true"
insert="true"
column="RENEWAL_DISCOUNT"
length="2"
/>

<property
name="homeOwnerDiscount"
type="java.lang.String"
update="true"
insert="true"
column="HOME_OWNER_DISCOUNT"
length="1"
/>

<property
name="previousCompanyNumber"
type="java.lang.String"
update="true"
insert="true"
column="PREV_COMP_NUMBER"
length="2"
/>

<property
name="previousPolicyPrefix"
type="java.lang.String"
update="true"
insert="true"
column="PREV_POLICY_PREFIX"
length="4"
/>

<property
name="previousPolicyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="PREV_POL_NUMBER"
length="9"
/>

<property
name="previousPolicyTermEffDate"
type="java.util.Date"
update="true"
insert="true"
column="PREV_TERM_EFF_DATE"
length="7"
/>

<property
name="previousPolicyTerm"
type="java.lang.Integer"
update="true"
insert="true"
column="PREV_POL_TERM"
length="3"
/>

<property
name="rewCompanyNumber"
type="java.lang.String"
update="true"
insert="true"
column="REW_COMP_NUMBER"
length="2"
/>

<property
name="rewPolicyPrefix"
type="java.lang.String"
update="true"
insert="true"
column="REW_POL_PREFIX"
length="4"
/>

<property
name="rewPolicyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="REW_POL_NUMBER"
length="9"
/>

<property
name="webUser"
type="java.lang.String"
update="true"
insert="true"
column="WEB_USER"
length="10"
/>

<set
name="units"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="POL_DETAILS_ID"
/>

<one-to-many
class="com.uaig.migration.history.oracle10g.vo.OraUnit"
/>
</set>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OraPolicyDetails.xml
containing the additional properties and place it in your merge dir.
-->

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.uaig.migration.history.oracle10g.vo.OraUnit"
table="UNITS"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="unitPK"
column="UNIT_ID"
type="java.lang.Integer"
unsaved-value="0"
>
<generator class="sequence">
<param name="sequence">UNITS_SEQ</param>
</generator>
</id>

<many-to-one
name="oraPolicyDetails"
class="com.uaig.migration.history.oracle10g.vo.OraPolicyDetails"
cascade="none"
outer-join="false"
update="true"
insert="true"
column="POL_DETAILS_ID"
not-null="true"
/>

<property
name="unitType"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_TYPE"
sql-type="char(2)"
/>
</property>

<property
name="unitGroup"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_GROUP"
sql-type="char(2)"
/>
</property>

<property
name="vinId"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="VIN_ID"
sql-type="varchar(25)"
/>
</property>

<property
name="unitYear"
type="java.lang.Integer"
update="true"
insert="true"
>
<column
name="UNIT_YEAR"
sql-type="number(4)"
/>
</property>

<property
name="unitMake"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_MAKE"
sql-type="char(4)"
/>
</property>

<property
name="unitModel"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_MODEL"
sql-type="varchar(10)"
/>
</property>

<property
name="description"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_DESCRIPTION"
sql-type="varchar(30)"
/>
</property>

<property
name="garageZipCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="GARAGE_ZIP_CODE"
sql-type="varchar(9)"
/>
</property>

<property
name="countyName"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="COUNTY_NAME"
sql-type="varchar(20)"
/>
</property>

<property
name="cityName"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="CITY_NAME"
sql-type="varchar(20)"
/>
</property>

<property
name="countyCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="COUNTY_CODE"
sql-type="char(5)"
/>
</property>

<property
name="unitStatus"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_STATUS"
sql-type="char(1)"
/>
</property>

<property
name="unitActivity"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_ACTIVITY"
sql-type="char(1)"
/>
</property>

<property
name="mileToWork"
type="java.lang.Integer"
update="true"
insert="true"
>
<column
name="MILES_TO_WORK"
sql-type="number(3)"
/>
</property>

<property
name="deleteDate"
type="java.util.Date"
update="true"
insert="true"
column="DELETE_DATE"
length="7"
/>

<property
name="addDate"
type="java.util.Date"
update="true"
insert="true"
column="ADD_DATE"
length="7"
/>

<property
name="ratedClass"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="RATED_CLASS"
sql-type="varchar(6)"
/>
</property>

<property
name="odometerReading"
type="java.lang.Integer"
update="true"
insert="true"
>
<column
name="ODOMETER_READ"
sql-type="number(7)"
/>
</property>

<property
name="ratedSymbol"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="RATED_SYMBOL"
sql-type="char(2)"
/>
</property>

<property
name="useCode"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="USE_CODE"
sql-type="char(2)"
/>
</property>

<property
name="territory"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="TERRITORY"
sql-type="char(3)"
/>
</property>

<property
name="passiveRest"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="PASSIVE_REST"
sql-type="char(2)"
/>
</property>

<property
name="antiTheft"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="ANTI_THEFT"
sql-type="char(2)"
/>
</property>

<property
name="antiLock"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="ANTI_LOCK"
sql-type="char(2)"
/>
</property>

<property
name="multiCar"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="MULTI_CAR"
sql-type="char(1)"
/>
</property>

<property
name="transferDiscount"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="TRANSFER_DIS"
sql-type="char(1)"
/>
</property>

<property
name="ratedPDriver"
type="java.lang.Integer"
update="true"
insert="true"
>
<column
name="RATED_P_DRIVER"
sql-type="number(3)"
/>
</property>

<property
name="replacementCost"
type="java.lang.Integer"
update="true"
insert="true"
>
<column
name="REPLACEMENT_COST"
sql-type="number(7)"
/>
</property>

<property
name="customEquipment"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="CUSTOM_EQUIPMENT"
sql-type="char(2)"
/>
</property>

<property
name="highSymbolSurch"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="HIGH_SYMBOL_SURCH"
sql-type="char(2)"
/>
</property>

<property
name="goodSafeDriver"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="GOOD_SAFE_DRIVER"
sql-type="char(1)"
/>
</property>

<property
name="unitChange"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="UNIT_CHANGE"
sql-type="char(1)"
/>
</property>

<property
name="vinChange"
type="java.lang.String"
update="true"
insert="true"
>
<column
name="VIN_CHANGE"
sql-type="char(1)"
/>
</property>

<property
name="unitNumber"
type="java.lang.Integer"
update="true"
insert="true"
>
<column
name="UNIT_NUMBER"
sql-type="number(3)"
/>
</property>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OraUnit.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


</class>

</hibernate-mapping>

AS400 MAPPING DOCS
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class
name="com.uaig.migration.history.as400.vo.HPolicy"
table="UQXXPLCY"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="referenceNumber"
column="UPREFNO"
type="java.lang.Integer"
>
<generator class="assigned">
</generator>
</id>

<property
name="policyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="UPPLNBR"
length="9"
/>

<property
name="policyPrefix"
type="java.lang.String"
update="true"
insert="true"
column="UPMPRFX"
length="4"
/>

<property
name="companyNumber"
type="java.lang.String"
update="true"
insert="true"
column="UPCOMP#"
length="2"
/>

<property
name="clientId"
type="java.lang.String"
update="true"
insert="true"
column="UPCLTID"
length="12"
/>

<property
name="generalAgent"
type="java.lang.String"
update="true"
insert="true"
column="UPGNAGT"
length="3"
/>

<property
name="subAgent"
type="java.lang.String"
update="true"
insert="true"
column="UPSBAGT"
length="6"
/>

<property
name="producingAgent"
type="java.lang.String"
update="true"
insert="true"
column="UPPDAGT"
length="9"
/>

<property
name="termEffectiveDate"
type="java.util.Date"
update="true"
insert="true"
column="UPTEFDT"
length="7"
/>

<property
name="termExpDate"
type="java.util.Date"
update="true"
insert="true"
column="UPTEXDT"
length="7"
/>

<property
name="accoutingDate"
type="java.util.Date"
update="true"
insert="true"
column="UPACTDT"
length="7"
/>

<property
name="entryDate"
type="java.util.Date"
update="true"
insert="true"
column="UPENTDT"
length="7"
/>

<property
name="policyTerm"
type="java.lang.Integer"
update="true"
insert="true"
column="UPTERM"
length="3"
/>

<property
name="policyPayPlan"
type="java.lang.String"
update="true"
insert="true"
column="UPPYPLN"
length="4"
/>

<property
name="policyState"
type="java.lang.String"
update="true"
insert="true"
column="UPSTATE"
length="2"
/>

<property
name="policyStatus"
type="java.lang.String"
update="true"
insert="true"
column="UPSTUS"
length="1"
/>

<property
name="policyActivity"
type="java.lang.String"
update="true"
insert="true"
column="UPACTY"
length="1"
/>

<property
name="policyType"
type="java.lang.String"
update="true"
insert="true"
column="UPPTYP"
length="2"
/>

<property
name="bindingNumber"
type="java.lang.String"
update="true"
insert="true"
column="UPBNDNO"
length="7"
/>

<property
name="quotedPremium"
type="java.math.BigDecimal"
update="true"
insert="true"
column="UPQTPRM"
length="11"
/>

<property
name="lastPremium"
type="java.math.BigDecimal"
update="true"
insert="true"
column="UPLSTPM"
length="11"
/>

<property
name="writtenPremium"
type="java.math.BigDecimal"
update="true"
insert="true"
column="UPWRTPM"
length="11"
/>

<property
name="policyFee"
type="java.math.BigDecimal"
update="true"
insert="true"
column="UPPLFEE"
length="11"
/>

<property
name="nonRenewalRes"
type="java.lang.Integer"
update="true"
insert="true"
column="UPMRNNS"
length="2"
/>

<property
name="renewalInd"
type="java.lang.String"
update="true"
insert="true"
column="UPMRENI"
length="1"
/>

<property
name="renewalDiscount"
type="java.lang.String"
update="true"
insert="true"
column="UPRNWDS"
length="2"
/>

<property
name="homeOwnerDiscount"
type="java.lang.String"
update="true"
insert="true"
column="UUHOMDS"
length="1"
/>

<property
name="previousCompanyNumber"
type="java.lang.String"
update="true"
insert="true"
column="UPPCMP"
length="2"
/>

<property
name="previousPolicyPrefix"
type="java.lang.String"
update="true"
insert="true"
column="UPPPFX"
length="4"
/>

<property
name="previousPolicyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="UPPPLN"
length="9"
/>

<property
name="previousPolicyEffDate"
type="java.util.Date"
update="true"
insert="true"
column="UPPTEFFDTE"
length="7"
/>

<property
name="previousPolicyTermEffDate"
type="java.util.Date"
update="true"
insert="true"
column="UPPTEXPDTE"
length="7"
/>

<property
name="previousPolicyTerm"
type="java.lang.Integer"
update="true"
insert="true"
column="UPPTERM"
length="3"
/>

<property
name="rewCompanyNumber"
type="java.lang.String"
update="true"
insert="true"
column="UPRCMP"
length="2"
/>

<property
name="rewPolicyPrefix"
type="java.lang.String"
update="true"
insert="true"
column="UPRPFX"
length="4"
/>

<property
name="rewPolicyNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="UPRPLN"
length="9"
/>

<property
name="webUser"
type="java.lang.String"
update="true"
insert="true"
column="UPUSER"
length="10"
/>
<!--
<set
name="drivers"
lazy="false"
inverse="true"
cascade="none"
>

<key>
<column name="UDREFNO"/>
</key>
<one-to-many
class="com.uaig.migration.history.as400.vo.Driver"
/>
</set>
-->
<set
name="units"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>
<key>
<column name="UUREFNO" />
</key>
<one-to-many
class="com.uaig.migration.history.as400.vo.Unit"
/>
</set>

<one-to-one name="insured"
class="com.uaig.migration.history.as400.vo.Insured"
cascade="save-update"/>
<!--
<set
name="endorsementForms"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<key>
<column name="UEREFNO" />
</key>
<one-to-many
class="com.uaig.migration.history.as400.vo.EndorsementForm"
/>
</set>

<set
name="fees"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>
<key>
<column name="UFREFNO" />
</key>
<one-to-many
class="com.uaig.migration.history.as400.vo.Fee"
/>
</set>
-->
</class>

</hibernate-mapping>

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.uaig.migration.history.as400.vo.Unit"
table="UQXXUNIT"
dynamic-update="false"
dynamic-insert="false"
>

<composite-id
name="unitPK"
class="com.uaig.migration.history.as400.vo.UnitPK"
>
<key-property
name="referenceNumber"
type="java.lang.Integer"
column="UUREFNO"
/>

<key-property
name="unitNumber"
type="java.lang.Integer"
column="UUNITNO"
/>
</composite-id>

<property
name="companyNumber"
type="java.lang.String"
column="UUCOMP#"
/>

<property
name="policyPrefix"
type="java.lang.String"
column="UUPRFXN"
/>

<property
name="policyNumber"
type="java.lang.Integer"
column="UUPLNBR"
/>

<property
name="unitType"
type="java.lang.String"
update="true"
insert="true"
column="UUNITTY"
length="2"
/>

<property
name="unitGroup"
type="java.lang.String"
update="true"
insert="true"
column="UUNITGR"
length="2"
/>

<property
name="vinId"
type="java.lang.String"
update="true"
insert="true"
column="UUVINID"
length="25"
/>

<property
name="unitYear"
type="java.lang.Integer"
update="true"
insert="true"
column="UUYEAR"
length="4"
/>

<property
name="unitMake"
type="java.lang.String"
update="true"
insert="true"
column="UUMAKE"
length="4"
/>

<property
name="unitModel"
type="java.lang.String"
update="true"
insert="true"
column="UUMODL"
length="10"
/>

<property
name="description"
type="java.lang.String"
update="true"
insert="true"
column="UUDESC"
length="30"
/>

<property
name="garageZipCode"
type="java.lang.String"
update="true"
insert="true"
column="UUZIPC"
length="9"
/>

<property
name="countyName"
type="java.lang.String"
update="true"
insert="true"
column="UUCNTY"
length="20"
/>

<property
name="cityName"
type="java.lang.String"
update="true"
insert="true"
column="UUCITY"
length="20"
/>

<property
name="countyCode"
type="java.lang.String"
update="true"
insert="true"
column="UUCNTCD"
length="5"
/>

<property
name="unitStatus"
type="java.lang.String"
update="true"
insert="true"
column="UUSTUS"
length="1"
/>

<property
name="unitActivity"
type="java.lang.String"
update="true"
insert="true"
column="UUACTY"
length="1"
/>

<property
name="mileToWork"
type="java.lang.Integer"
update="true"
insert="true"
column="UUMILE"
length="3"
/>

<property
name="deleteDate"
type="java.util.Date"
update="true"
insert="true"
column="UUDELDT"
length="7"
/>

<property
name="addDate"
type="java.util.Date"
update="true"
insert="true"
column="UUADDDT"
length="7"
/>

<property
name="ratedClass"
type="java.lang.String"
update="true"
insert="true"
column="UURCLS"
length="6"
/>

<property
name="odometerReading"
type="java.lang.Integer"
update="true"
insert="true"
column="UUODOM"
length="7"
/>

<property
name="ratedSymbol"
type="java.lang.String"
update="true"
insert="true"
column="UURSYMB"
length="2"
/>

<property
name="useCode"
type="java.lang.String"
update="true"
insert="true"
column="UUPUSEC"
length="2"
/>

<property
name="territory"
type="java.lang.String"
update="true"
insert="true"
column="UUTERR"
length="3"
/>

<property
name="passiveRest"
type="java.lang.String"
update="true"
insert="true"
column="UUPSRT"
length="2"
/>

<property
name="antiTheft"
type="java.lang.String"
update="true"
insert="true"
column="UUANTF"
length="2"
/>

<property
name="antiLock"
type="java.lang.String"
update="true"
insert="true"
column="UUANTLK"
length="2"
/>

<property
name="multiCar"
type="java.lang.String"
update="true"
insert="true"
column="UUMULTC"
length="1"
/>

<property
name="transferDiscount"
type="java.lang.String"
update="true"
insert="true"
column="UUTRNFD"
length="1"
/>

<property
name="ratedPDriver"
type="java.lang.Integer"
update="true"
insert="true"
column="UURTDRV"
length="3"
/>

<property
name="replacementCost"
type="java.lang.Integer"
update="true"
insert="true"
column="UURPLCT"
length="7"
/>

<property
name="customEquipment"
type="java.lang.String"
update="true"
insert="true"
column="UUCUSTE"
length="2"
/>

<property
name="highSymbolSurch"
type="java.lang.String"
update="true"
insert="true"
column="UUHGSYM"
length="2"
/>

<property
name="goodSafeDriver"
type="java.lang.String"
update="true"
insert="true"
column="UUSNRDR"
length="1"
/>

<property
name="unitChange"
type="java.lang.String"
update="true"
insert="true"
column="UUNITCH"
length="1"
/>

<property
name="vinChange"
type="java.lang.String"
update="true"
insert="true"
column="UUVINCH"
length="1"
/>

<many-to-one
name="policy"
class="com.uaig.migration.history.as400.vo.HPolicy"
cascade="none"
outer-join="auto"
update="false"
insert="false"
>
<column
name="UUREFNO"
/>
</many-to-one>

<set
name="coverages"
lazy="false"
inverse="true"
cascade="none"
sort="unsorted"
>
<key>
<column name="UCREFNO" />
<column name="UCNITNO" />
</key>

<one-to-many
class="com.uaig.migration.history.as400.vo.Coverage"
/>
</set>

<one-to-one name="leanHolder"
class="com.uaig.migration.history.as400.vo.LeanHolderInfo"
cascade="save-update"/>

</class>
</hibernate-mapping>




try{...
String query = "select pol from HPolicy pol where pol.referenceNumber in(600100)"; //just load one obj for testing purposes
Query q = as400Session.createQuery(query);

ScrollableResults result = q.scroll();
int count = 0;
while ( result.next() ) {

HPolicy as400Pol = (HPolicy) result.get(0);
OraPolicy policy = new OraPolicy();

//compose the policy
OraPolicyDetails oraPolDetails = new OraPolicyDetails();
BeanUtils.copyProperties(oraPolDetails, as400Pol);

//compose the units
Set as400Units = as400Pol.getUnits();
Object [] units = srcUnits.toArray();
for(int i = 0; i < units.length; i++){
OraUnit oraUnit = new OraUnit();
Unit as400Unit = (Unit)units[i];
BeanUtils.copyProperties(oraUnit, as400Unit);

//set the values from the composite key
oraUnit.setUnitNumber(as400Unit.getUnitPK().getUnitNumber());

//add it to the Set - Set the relationships
oraPolDetails.addUnits(oraUnit);
}

//save the oracle object - Why Illegal attempt to associate a collection with two open sessions message
oraSession.save(policy);

if ( ++count % 20 == 0 || count == rows) {
//log.info("Flushing/Clearing sessions " + count);
as400Session.flush();
as400Session.clear();
oraSession.flush();
oraSession.clear();
}
}
//close Oracle and AS400 sessions
oraTx.commit();
oraSession.close();
as400Tx.commit();
as400Session.close();
}
catch...


net.sf.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at net.sf.hibernate.collection.PersistentCollection.setCurrentSession(PersistentCollection.java:257)
at net.sf.hibernate.impl.WrapVisitor.processCollection(WrapVisitor.java:42)
at net.sf.hibernate.impl.AbstractVisitor.processValue(AbstractVisitor.java:69)
at net.sf.hibernate.impl.WrapVisitor.processValues(WrapVisitor.java:93)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:931)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:868)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:790)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:749)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1398)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:962)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:868)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:790)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:749)
at com.uaig.migration.dao.BaseDAO.findSavePoliciesForHistoryInitialImport(BaseDAO.java:281)
at com.uaig.migration.core.EndorsementHistoryMigration.run(EndorsementHistoryMigration.java:27)
at com.uaig.migration.core.EndorsementHistoryMigration.main(EndorsementHistoryMigration.java:17)


Name and version of the database you are using: Oracle 10g


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 3:46 pm 
Newbie

Joined: Tue Oct 05, 2004 11:22 am
Posts: 8
I have seen this error when I tried to set a reference to the same mapped (Java) collection in two different persisted classes. I solved it by making a new Java collection and copying the references from the collection to a new one (addAll). You might not be able to get away with using bean utils to copy a deep object.


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.