Hello!
We are currently using Hibernate 3.2.4.
We have the following mapping question:
We have three objects types/tables:
Type A: Some business object
Type B: Some depending business object
Type C: Some table that defines time slices.
A, B and C have normal primary keys, A and B also have logical keys that mark object of some logical indentity for different time slices.
C defines time slices. Objects of B (and also of A, but that is out of scope for this question) with different primary key and the same logical key point to different time slices and in fact one row of B can even have multiple assigned time slices, so that there is a "one to many" relation between B and C, too.
As a result A and B have a "1 to many" relation if joining over this logical key. Rows in A point to multiple rows in B since there are different matching rows in B depending on the time slice defined by C ( C contains entries with an "from" date and an additional optional "to" date).
However while the table layout defines a "1 to many" relation between A and B and B and C in our application infact there is always logically a one two one relation between A and B because there is exactly one row in B that matches a row in A *at one point of time*. Selects over A and B (and C) will always contain an additional WHERE criterium that selects exactly one row in B (via a join to C).
The problem: If we model the mapping to define a "one to one" relation, hibernate may get problems when the WHERE is left out accidently. However if we map a "one to many" relation we need to define a Collection type in the java objects for table A - which is ugly on the java side.
Currently our code defines no realtion between the table at all and loads depending instance of B manually - which is ugly. Also its seems like using DetachedCriteria one cannot define a join over A and B, since hibernate cannot see the relation looking at the mappings. And DetachedCriteria are nice :-)
Is there a way to write some mapping that allows us to map the physical :n relation onto a 1:1 relation and a additional WHERE criterium? Or are there nay features in hibernate to help us smooth the java side.
Any hint to some code or documention fragment and a general solution strategie would be helpful.
Thanks for any help!
Gruß...Tim
_________________ Gruß...
Tim
|