-->
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.  [ 4 posts ] 
Author Message
 Post subject: Collection Loader Questions
PostPosted: Fri Oct 14, 2005 2:43 am 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
Hibernate version:3.1RC1
Database: SQL Server 2000

Hi,

1) I can't seem to get collection loaders to work at all. I made my mapping as close to the example from the documentation (down below) and Hibernate just ignores the <loader/> element. In other words, the behavior is the exact same whether or not <loader/> is there (and it is odd behavior, ask for details if you want to hear it). Is it just not implemented in RC1 yet?

2) I'm a little confused on the example below. I know how you normally bind named filter parameters to a query a runtime. But how would you do that on a collection loader query?? In the example below, in <sql-query/>, does the :id parameter have an automatic implied binding to the id property of the Person class? That is actually the behavior that I would like to see, but nothing says that but I'm not sure how else you'd use it.


Code:
<class name="Person">
    <id name="id">
        <generator class="increment"/>
    </id>
    <property name="name" not-null="true"/>
    <loader query-ref="person"/>
</class>

<set name="employments" inverse="true">
    <key/>
    <one-to-many class="Employment"/>
    <loader query-ref="employments"/>
</set>

<sql-query name="employments">
    <load-collection alias="emp" role="Person.employments"/>
    SELECT {emp.*}
    FROM EMPLOYMENT emp
    WHERE EMPLOYER = :id
    ORDER BY STARTDATE ASC, EMPLOYEE ASC
</sql-query>


Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 10:48 am 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
One clarification to my post above regarding this statement "and it is odd behavior, ask for details if you want to hear it". Scratch that. Now that I think about it, it is not odd.... but more importantly it is completely irrelevant to the rest of my post...

But the questions remain..
Is collection loader implemented in 3.1 rc1? If so, what would cause HB to ignore the <loader/> mapping? In the documentated code example what is :id bound to?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 3:11 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
So.... collection loaders are there but we shouldn't use them... or... ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 4:36 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
Allrighty then... is anybody alive out there? I've spent a lot of time on this and am getting nowhere. I even bought the book which has nothing on this. Maybe there's a little piece of documentatin I'm overlooking... either way, all that matters is I'm stuck.

So let's try this another way...

Anybody know why the <loader/> element would be completely ignored in the simplified example below? I can mangle the query-ref property to point to a query that doesn't exist... no error. I can take the entire element out, my query results are the same no matter what. I even tried upgrading to 3.1rc2.

I'm just doing a straight HQL query to test the results... maybe I'm supposed to do something special in HQL??

Code:
select ut.units from UnitType ut

.. gives me ALL units, not "where unit.type_id = 5"

Code:
<class name="UnitType">
....
   <set name="units" invers="true">
      <key/>
      <one-to-many class="Unit"/>
      <loader query-ref="units.collection.query"/>
   </set>
</class>
     
<sql-query name="units.collection.query">
   <load-collection alias="unit" role="UnitType.units"/>
   select {unit.*} from unit where unit.type_id = 5
</sql-query>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.