-->
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: A simple attempt to understand HQL join
PostPosted: Mon Mar 20, 2006 6:19 pm 
Beginner
Beginner

Joined: Thu Feb 23, 2006 11:22 am
Posts: 30
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
hibernate 3.1


the Question:(mapping docs and detail appear after question)

Looking at the Hibernate Reference manual, Chapter 14: The Hibernate Query Language. I have a newbie question and was hoping that someone could shed some light on it. Here is the HQL Query from the reference manual:

“from Cat as cat join cat.mate as mate left join cat.kittens as kitten”

Perhaps my mind has been corrupted by SQL but this does not seem to make sense to me.
The Cat object has a member variable called mate and a java.util.Set called kittens. So this means show me all the kittens that this cat has from her current mate? Is that right? What do I get back from this HQL query? Kitten objects or Cat objects? Or an object that is an amalgamation / abomination of both objects?

There are no explanations of the HQL statements in the reference manual rendering Chapter 14 of little value (sincere apologies to the authors). Nor does there seem to be any decent tutorials out there that cover anything past the very simple basics. Admittedly, to most HQL people, this question is simple, and basic, and I no doubt will feel the same once I gain a basic understanding of HQL.

When I do a join in SQL I have two tables that I am joining and I get back a cross of both tables. If a table is now an object, what are the two objects that this join is operating on. One is Cat and then other is… ? The objects in the set known as kittens? Is that what is happening.

Can someone explain this.. I am sending two simple mapping files along and with a small code chunk which seems to return zero objects... ie throws a null pointer exception in the createQuery().list(); command...

Thanks
Learning to be a good dog..

Mapping documents:
content detail points to content data records.. I am not interested in mapping right now. I have all that working just fine.. I need to understand HQL and complex joining..

----------------------------- content_detail the parent
<hibernate-mapping package="hibernate.pojo">

<class name="ContentDetail" table="content_detail">
<id name="detailId" column="detail_id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<!-- dim5Member does not require an Alis in the query -->
<property name="dim5Member" column="dim5_member" type="java.lang.String" />
<property name="metricName" column="metricName" type="java.lang.String" />
<property name="inuse" column="inuse" type="java.lang.Boolean" not-null="true" />

<!--
<many-to-one name="contentMaster" column="master_id" class="ContentMaster" not-null="true" />

<set
name="dataSet"
table="content_data"
cascade="all-delete-orphan">
<key column="detail_id"/>
<one-to-many class="ContentData"/>
</set>
-->
</class>

</hibernate-mapping>
--------------------------------------------------- content_data (the child)
<hibernate-mapping package="hibernate.pojo">

<class name="ContentData" table="content_data">
<id name="dataId" column="data_id" type="java.lang.Integer">
<generator class="increment"/>
</id>

<property name="period" column="period" type="java.lang.String" not-null="true" />
<property name="actual" column="actual" type="java.lang.Float" />
<property name="target" column="target" type="java.lang.Float" />
<property name="ready" column="ready" type="java.lang.Integer" not-null="true" />

<!-- <many-to-one name="contentDetail" column="detail_id" class="ContentDetail" />-->
</class>

</hibernate-mapping>

note: the dtd spec is wrong, our software is not at Java 5.0 yet.. I am working on that..


Code between sessionFactory.openSession() and session.close():
here is my attempt to do a join in HQL
String HQLString = "from ContentDetail as detail join detail.metricName as name left join detail.dataset as data";

List results = session.createQuery(HQLString).list();
String[] rows = super.toRow(HQLString, results);


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.