[hibernate-dev] Regarding Alex Bacon's "Major issue with Hibernate Filters" circa Sept 11, 2006...

Edmund Grossenbacher egrossenbacher at alterpoint.com
Wed Dec 13 13:01:47 EST 2006


I have a similar situation to what Alex Bacon described in his "Major
issue with Hibernate Filters" thread in September, and I'm wondering if
there was ever a palatable resolution.
 
The basic notion is that I have an object graph consisting of
relationships of varying multiplicity.  For various reasons I wish to
introduce "effective dates" into the database.  The documented Filter
example of Employee and Department pretty much illustrates the idea.
Lets say that at any given time, an Employee belongs to one Department,
and a Department has multiple employees (so Department has a one-to-many
bidirectional relationship with Employee.)  Employee contains a foreign
key back to Department, which is the canonical way to represent
one-to-many relationships in the database - by putting a foreign key on
the "many" side.
 
Over time, an employee can move between departments, so without
considering time the relationship between Employee and Department is
many-to-many.  Note that I don't actually need a many-to-many join table
here: Employee still contains an FK back to Department, and a given
Employee ID now appears multiple times in the Employee table with
non-overlapping "effective date" time intervals.  At particular point in
time, only ONE Employee row is effective.
 
I only care about the relationships that exist at particular points in
time.  Therefore, I wish to apply a Filter that *I know* will always
produce a one-to-many relationship between Department and Employee.
Steve's comment suggests that this is a misapplication of "Filter" -
because to assume that Filter will slice the one-to-many relationship
(at a single point in time) out of the many-to-many relationship that is
actually stored in the database would be using Filters to change
multiplicity, and that is apparently NOT the intent.
 
Fine:  so forget Filters.  Is there another way to get this same effect?
I know one way:  I can create views that reproduce the "full" object
graph at each point in time that is of interest.  Those views will have
the correct one-to-many (or one-to-one) relationships in them. I could
then map the views with Hibernate.  The downside here is, I *also* need
to map the "current time" of the real underlying tables, so that I can
manipulate them to write updates.  That means I need essentially two
mappings of the same set of objects, which sounds like more work.
 
The "Filter" concept seems so close to what I want...  If Entity-level
Filters are ALWAYS applied to generated SQL it seems like this would
work, at least if I always enable the Filter before doing any operations
involving timesliced entities.  If autoenabled Filters were present (per
ANN-433) it seems like the solution would be even sweeter.
 
Has anyone had REAL experience using timeslicing (effective dates, etc)
in the database and mapping the single-point-in-time results with
Hibernate?  I've seen this pattern in several databases in my career -
although typically it seems to appear in warehouse environments more
than in production databases..;
 
-ed
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-dev/attachments/20061213/c2778018/attachment.html 


More information about the hibernate-dev mailing list