-->
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: how does the "loader" for a "set" work?
PostPosted: Thu Jun 25, 2009 12:18 pm 
Newbie

Joined: Thu Jun 25, 2009 7:22 am
Posts: 9
Hello,

I have two persistent classes: Account and Transaction with the following hibernate mapping:
Code:
   <class name="Account" table="account">
      <id name="id" length="10">
         <generator class="native"/>
      </id>
      <set name="transactions" table="transaction" inverse="true">
         <key/>
         <one-to-many class="Transaction"/>
         <loader query-ref="transactions"/>
      </set>
   </class>
   <class name="minibank.model.Transaction" table="transaction">
      <id name="id" length="10">
         <generator class="native"/>
      </id>
      <many-to-one name="from" column="`from`" class="Account" not-null="true"/>
      <many-to-one name="to" column="`to`" class="Account" not-null="true"/>
   </class>
   <sql-query name="transactions">
      <load-collection alias="tra" role="Account.transactions"/>
      select {tra.*}
      from transaction tra
      where tra.from=:id or tra.to=:id
   </sql-query>

That means, each transaction is related to two accounts ("from" and "to") and an account shall reference all transactions (via the set "transactions") that are related this account.

The problem is that this mapping does not work as expected. I'm wondering what hibernate does when I call account.getTransactions(). I thought it should be equivalent to this code:
Code:
List<Transaction> acc = session.getNamedQuery("transactions").setParameter("id", account.getId()).list();

But it's actually not! The second variant works and returns me the full list of related transaction whereby account.getTransactions() returns only a subset of those transactions.

Does someone know why it's not the same or what I'm doing wrong?


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.