-->
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: Problem retrieving collection into bag
PostPosted: Wed Apr 18, 2007 12:59 pm 
Newbie

Joined: Wed Apr 18, 2007 12:41 pm
Posts: 2
I can't seem to figure out why my configuration is behaving this way and I will do my best in explaining the problem.
I have an account table that has a composite id of customer_id,rt_num,acct_num, I also have a transaction table.
In the Account object I have a list of transactions, I can add to this list and have it save off to the database just fine, but when I query the database the logs show that it finds the value but it does not add the transaction object to the list.

Mapping documents:
Code:
<!-- Account mapping -->
<hibernate-mapping>
    <class name="AccountImpl" table="account">
        <composite-id name="id" class="AccountIdImpl">
            <key-property name="customerId" type="long">
                <column name="CUSTOMER_ID" length="9" />
            </key-property>
            <key-property name="rtNum" type="long">
                <column name="RT_NUM" length="9" />
            </key-property>
            <key-property name="acctNum" type="string">
                <column name="ACCT_NUM" length="17" />
            </key-property>
        </composite-id>
        ...other properties...
        <!-- Associations -->
        <bag name="transaction" inverse="true" cascade="save-update">
            <key>
               <column name="CUSTOMER_ID"/>
               <column name="RT_NUM"/>
               <column name="ACCT_NUM"/>
            </key>
            <one-to-many class="TransactionImpl"/>
        </bag>
       
    </class>
</hibernate-mapping>

<!-- Account mapping -->
<hibernate-mapping>
    <class name="TransactionImpl" table="transaction">
        <id name="refId" type="long">
            <column name="REF_ID" length="9" />
            <generator class="sequence">
           <param name="sequence">trans_seq</param>
        </generator>
        </id>
        <property name="acctType" type="long">
            <column name="ACCT_TYPE" length="5" />
        </property>
        <property name="bankName" type="string">
            <column name="BANK_NAME" length="45" />
        </property>
        <property name="amount" type="double">
            <column name="AMOUNT" length="12" />
        </property>
        <property name="schedDate" type="date">
            <column name="SCHED_DATE" length="10" />
        </property>
        <property name="byWho" type="string">
            <column name="BY_WHO" length="100" />
        </property>
       
        <many-to-one name="account" class="AccountImpl">
           <column name="CUSTOMER_ID"/>
           <column name="RT_NUM"/>
           <column name="ACCT_NUM"/>
        </many-to-one>
    </class>
</hibernate-mapping>



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

Debug level Hibernate log excerpt:
Code:
2007-04-18 09:21:09,208 DEBUG [net.sf.hibernate.SQL] - select transac0_.customer_ID as customer_ID__, transac0_.RT_NUM as RT_NUM__, transac0_.ACCT_NUM as ACCT_NUM__, transac0_.REF_ID as REF_ID__, transac0_.REF_ID as REF_ID0_, transac0_.ACCT_TYPE as ACCT_TYPE0_, transac0_.BANK_NAME as BANK_NAME0_, transac0_.AMOUNT as AMOUNT0_, transac0_.SCHED_DATE as SCHED_DATE0_, transac0_.BY_WHO as BY_WHO0_, transac0_.customer_ID as customer_ID0_, transac0_.RT_NUM as RT_NUM0_, transac0_.ACCT_NUM as ACCT_NUM0_ from _transaction transac0_ where transac0_.customer_ID=? and transac0_.RT_NUM=? and transac0_.ACCT_NUM=?
2007-04-18 09:21:09,395 DEBUG [net.sf.hibernate.loader.Loader] - result set contains (possibly empty) collection: [AccountImpl.Transaction#AccountIdImpl@bbaa16[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,395 DEBUG [net.sf.hibernate.loader.Loader] - result row: 191592
2007-04-18 09:21:09,395 DEBUG [net.sf.hibernate.loader.Loader] - found row of collection: [AccountImpl.Transaction#AccountIdImpl@1d86a73[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,473 DEBUG [net.sf.hibernate.impl.SessionImpl] - resolving associations for [TransactionImpl#191592]
2007-04-18 09:21:09,473 DEBUG [net.sf.hibernate.SQL] - select account0_.customer_ID as customer_ID0_, account0_.RT_NUM as RT_NUM0_, account0_.ACCT_NUM as ACCT_NUM0_, account0_.BANK_NAME as BANK_NAME0_, account0_.ACCT_NAME as ACCT_NAME0_, account0_.ACCT_TYPE as ACCT_TYPE0_, account0_.PRENOTE_DATE as PRENOTE_7_0_, account0_.SEQ_ID as SEQ_ID0_, account0_.DISABLED_YN as DISABLED9_0_, account0_.UPDT_DTM as UPDT_DTM0_ from _account account0_ where account0_.customer_ID=? and account0_.RT_NUM=? and account0_.ACCT_NUM=?
2007-04-18 09:21:09,645 DEBUG [net.sf.hibernate.loader.Loader] - result row: AccountIdImpl@12b4986[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - resolving associations for [AccountImpl#AccountIdImpl@12b4986[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - done materializing entity [AccountImpl#AccountIdImpl@12b4986[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - done materializing entity [TransactionImpl#191592]
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - 2 collections were found in result set
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - collection fully initialized: [AccountImpl.Transaction#AccountIdImpl@1d86a73[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - collection fully initialized: [AccountImpl.Transaction#AccountIdImpl@bbaa16[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.impl.SessionImpl] - 2 collections initialized
2007-04-18 09:21:09,739 DEBUG [net.sf.hibernate.SQL] - select transac0_.customer_ID as customer_ID__, transac0_.RT_NUM as RT_NUM__, transac0_.ACCT_NUM as ACCT_NUM__, transac0_.REF_ID as REF_ID__, transac0_.REF_ID as REF_ID0_, transac0_.ACCT_TYPE as ACCT_TYPE0_, transac0_.BANK_NAME as BANK_NAME0_, transac0_.AMOUNT as AMOUNT0_, transac0_.SCHED_DATE as SCHED_DATE0_, transac0_.BY_WHO as BY_WHO0_, transac0_.customer_ID as customer_ID0_, transac0_.RT_NUM as RT_NUM0_, transac0_.ACCT_NUM as ACCT_NUM0_ from _transaction transac0_ where transac0_.customer_ID=? and transac0_.RT_NUM=? and transac0_.ACCT_NUM=?
2007-04-18 09:21:09,911 DEBUG [net.sf.hibernate.loader.Loader] - result set contains (possibly empty) collection: [AccountImpl.Transaction#AccountIdImpl@12b4986[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:09,911 DEBUG [net.sf.hibernate.loader.Loader] - result row: 191592
2007-04-18 09:21:09,911 DEBUG [net.sf.hibernate.loader.Loader] - found row of collection: [AccountImpl.Transaction#AccountIdImpl@1d314cc[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:10,005 DEBUG [net.sf.hibernate.impl.SessionImpl] - 2 collections were found in result set
2007-04-18 09:21:10,005 DEBUG [net.sf.hibernate.impl.SessionImpl] - collection fully initialized: [AccountImpl.Transaction#AccountIdImpl@1d314cc[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]
2007-04-18 09:21:10,005 DEBUG [net.sf.hibernate.impl.SessionImpl] - collection fully initialized: [AccountImpl.Transaction#AccountIdImpl@12b4986[
  customerId=123456789
  rtNum=12333054
  acctNum=345742
]]



Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 5:45 pm 
Newbie

Joined: Wed Apr 18, 2007 12:41 pm
Posts: 2
I found my problem...whenever you are having problems with composite ids, or keys first place to look....the equals and hashCode methods for that composite class. The equals/hashCode method generated by an eclipse tool caused this association to break. I removed those methods and used some reflection comparison and hashcode generation and it fixed the problem.


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.