-->
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: one-to-many relation between two elements of same type
PostPosted: Wed Feb 06, 2008 9:57 am 
Newbie

Joined: Wed Feb 06, 2008 8:58 am
Posts: 3
Hibernate version: 3
Database: MySQL 5.1.22

Hi,
I am hanging on this problem for quite some time. Unfortuately I wasn't able to find any help using the forum search or google.

I have a Database table "disco_lad" with the columns "id" (PK), "tour_nr", "gst" and some others that simply contain additional information. id is the Primary Key field, tour_nr is set on some records and is null on most. gst is simply a numeric property defining a department.

Whenever the two fields tour_nr and gst are equal to that of another record, these are grouped together. All of these grouped elements are equal of priority. One out of each group becomes the primary record and the rest are children of the primary.

I would now like to have a Set inside "DiscoLad" returning a set of "DiscoLad" Objects, that belong to the same group.

I have a SQL Statement I used to use before migrating to hibernate ...

SELECT prim.*, sec.* FROM
(SELECT *, IF(tour_nr IS NULL, CONCAT('X', id), tour_nr) AS virt_tour_nr FROM disco_lad GROUP BY virt_tour_nr, gst) AS prim
LEFT JOIN
disco_lad AS sec
ON prim.virt_tour_nr = sec.tour_nr AND prim.gst = sec.gst AND prim.id != sec.id

Unfortunately I am totally stuck in how I would model this relation in Hibernate :-(

Any Help greatly appreciated


Top
 Profile  
 
 Post subject: Non-Hibernate Solution
PostPosted: Thu Feb 07, 2008 3:53 am 
Newbie

Joined: Wed Feb 06, 2008 8:58 am
Posts: 3
Hi,

I managed to solve my problem without the need of any crazy Hibernate stuff. Unfortunately I would have liked to hear a Hibernate solution for this problem. I'll start another thread for this, since the topic is sort of confusing.

My solution currently selects all records and a component pre-processes the resulting collection. I think this is way faster than leting the DB or Hibernate do anything.

Regards, Chris


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.