-->
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: problems with 'join'
PostPosted: Sat Oct 02, 2010 9:00 am 
Newbie

Joined: Sat Oct 02, 2010 8:39 am
Posts: 2
On a start, hello to everyone!

I have two classes
Code:
class Source{
  int id;
  Set<Thread> threads;
  String lang;
   ...  // other fields, getters and setters
}

class Thread{
   long id;
   Source parent;
   String lang;
   ...  // other fields, getters and setters
}
and mappings
Code:
<class name="Source" table="source">
      <id name="id">
         <generator class="native" />
      </id>
      <property name="lang" length="5" />
      <set name="threads" inverse="true">
         <key column="thread_id" not-null="true" />
         <one-to-many class="Thread" />
      </set>
   </class>

   <class name="Thread" table="thread">
          <id name="id" column="thread_id">
         <generator class="native" />
      </id>
      <many-to-one name="source" column="source_id" class="ThreadsSource" />
                <!-- point of interrest -->
      <join table="source"  >
         <key foreign-key="source_id" >
            <column name="id"  />
         </key>
         <property name="lang" update="false" insert="false" />
      </join>
   </class>
I want 'lang' property from Source class to be populated over it's Threads (i want 'source' property to be loaded lazy and 'lang' property fetched from 'source' table immediately and placed into Thread class). Hibernate is placing 'lang' property in SQL queury but it's join fragment is like this:
Quote:
join source on thread.thread_id = source.id

and it should be:
Quote:
join source on thread.source_id = source.id

There is no change if I remove 'foreign-key' parameter from '<key ...' or when i place 'inverse' into the '<join ...'.

I would be greatful if you help me with it.
Thanks
Piotrek
---
hibernate 3.3.0.SP1
on 3.5.6-Final too


Top
 Profile  
 
 Post subject: Re: problems with 'join'
PostPosted: Mon Oct 04, 2010 3:06 am 
Newbie

Joined: Sat Oct 02, 2010 8:39 am
Posts: 2
I see that it isn't clear

Is it possible to gain this with single HQL query without using object[]{ Thread t, String lang} ?

Something like
Quote:
from Thread t, set t.lang = t.source.lang
?
Will it initialize 'source' property? If so, it's useless.
Thanks


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.