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
|