-->
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: self-referencing table
PostPosted: Tue Mar 23, 2004 10:49 am 
Newbie

Joined: Tue Mar 23, 2004 10:40 am
Posts: 9
Location: toronto
Hi there,

I have searched the forums for self-referencing postings but could not find any.

I have created a table that has a foreign key to itself to create a parent-child relationship (1 parent can have many children). I would like to know what hibernate query to run to get a list of all rows with their self-reference attributes populated.

Thanks in advance :)

Here is the mapping file (created by middlegen):
-----------
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC

"-//Hibernate/Hibernate Mapping DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >



<hibernate-mapping>

<!--

Created by the Middlegen Hibernate plugin



http://boss.bekk.no/boss/middlegen/

http://hibernate.sourceforge.net/

-->



<class

name="com.crisys.sf.dto.PerspectiveElement"

table="PerspectiveElement"

>



<id

name="id"

type="java.lang.String"

column="id"

>

<generator class="assigned" />

</id>



<property

name="perspectiveName"

type="java.lang.String"

column="PerspectiveName"

not-null="true"

length="50"

/>

<property

name="className"

type="java.lang.String"

column="ClassName"

not-null="true"

length="100"

/>

<property

name="context"

type="java.lang.String"

column="Context"

length="100"

/>

<property

name="position"

type="java.lang.String"

column="Position"

length="50"

/>



<!-- associations -->

<!-- bi-directional one-to-many association to PerspectiveElement -->

<set

name="perspectiveElements"

lazy="true"

inverse="true"

>

<key>

<column name="Parent" />

</key>

<one-to-many

class="com.crisys.sf.dto.PerspectiveElement"

/>

</set>

<!-- bi-directional many-to-one association to PerspectiveElement -->

<many-to-one

name="perspectiveElement"

class="com.crisys.sf.dto.PerspectiveElement"

not-null="true"

>

<column name="Parent" />

</many-to-one>



</class>

</hibernate-mapping>

_________________
Be happy :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 23, 2004 11:43 am 
Newbie

Joined: Mon Mar 15, 2004 8:55 am
Posts: 2
Location: Germany
A good way to determine a HSQL query is to write down the query in SQL
first. Then replace tablenames by classnames, fields by attributes.
It would be helpful, if you could post your SQL-Statement.

Jens


Top
 Profile  
 
 Post subject: almost there :)
PostPosted: Wed Mar 24, 2004 9:31 am 
Newbie

Joined: Tue Mar 23, 2004 10:40 am
Posts: 9
Location: toronto
Thanks Jens,

Ive got a query in HQL now that is close to correct. This returns x number of objects which each have 0 to n children in their set.

What I would like the query to do is go through the children and do the join for their children recursively (untill it reaches a row that has no children). The result would be a set of graphs.

Here is my query so far (each PerspectiveElement contains a set of children, called perspectiveElements).
----------------------------------

"from PerspectiveElement as pe left join fetch pe.perspectiveElements"

_________________
Be happy :)


Top
 Profile  
 
 Post subject: found the answer
PostPosted: Wed Mar 24, 2004 10:58 am 
Newbie

Joined: Tue Mar 23, 2004 10:40 am
Posts: 9
Location: toronto
Need to make lazy = false for the set of children as follows

<set
name="perspectiveElements"
lazy="false"
inverse="true"
>

_________________
Be happy :)


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.