-->
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.  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Time-Slices Entities
PostPosted: Fri Mar 26, 2004 4:50 pm 
Newbie

Joined: Fri Mar 26, 2004 4:36 pm
Posts: 1
We've an application that bases on 'time-sliced' object. I don't know a better expression for this but I'll explain what I mean:
Let's say we have an object called Person with attributes/properties like lastname, firstname, dateofbirth, address etc. Quite common stuff. Now the difference is that we're not only interested in where the person lives at the moment but also where he's lived say one year before now or even one year from now.
The database tables (legacy system) look like the following:

Table Person: Number (INT), From (DATE), Until (DATE), FirstName (VARCHAR), LastName
Table Address: PersonNumer (INT, Foreign Key), From (DATE), Until (DATE), Street, City, Country

So we have foreign keys that don't directly refere to a database row but rather to a bunch of it (with different validity dates).

Now the question is how to project this onto an object model. We've something like an object Person that has methods like PersonSlice getData(java.util.Date per); in mind. Is something like this possible with hibernate (the slices shouldn't be much of a problem, but the 'container'-Object is (since it's composed by multiple-rows).
Are there any best practices for such 'time-slice' handling? (is there an actual name for this?) Is our idea of the object model right or are we missing something that would make it so simple you can't believe you've never thought of it?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 4:54 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
I have something like this, though I do not slice persons, but
information -

I have [information piece] 1 --> n [information version] 1-1 [polymorphic content]

piece-version is a map ( for example keyed by date / msecs / whatever ) , and you can have service methode "get version as of
date" peeking into this map ( and of course "get actual one" )




And content is separated from version because it can be big, complicated and change its type from time to time ( for example from text to video )

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 5:14 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
I think Fowler's article on Temporal Patterns is a great place to start:

http://www.martinfowler.com/ap2/timeNarrative.html

He defines a "snapshot" to be the state of an object at a specific point in time. This is, I believe, equivalent to your time-slices.

If you want to go deep, you could check out this book:

http://books.elsevier.com/us//mk/us/sub ... 5860-855-9


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 27, 2004 7:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The Chris Date book about temporal data is not easy to read, forget it if you don't know his other books and work. It's a fight.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 10, 2004 5:51 am 
Newbie

Joined: Tue Aug 10, 2004 5:02 am
Posts: 1
Location: Guildford, UK
I came across these posts when searching on "temporal".
I have the same requirement as the initial poster, but I don't feel I have a good solution yet.

I have a data model with start and end dates that allow "effectivity".

I've seen Fowler's patterns on temporal data and understand how this works in the object world. I'm new to Hibernate and what I can't figure out yet is how to map Temporal Property or Temporal Object using hibernate mapping.

Has anyone got an example of how they have done this?

Help would be really appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 15, 2004 5:56 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Time to give this a bump as I am faced with the same type of temporal problem and so far praying for Divine Intervention for a solution hasn't worked too well.

I'm in a situation where I have multiple tables within my object model that are date effective. In my situation, the end user has the ability to go back in time in order to issue amendments on this time sensitive data.

So imagine a fairly basic data graph where A -< B -< C.

If only C were date effective I think the scenario becomes pretty basic. i.e. I multiple physical Cs and I can use hib 3's filter functionality in order to pare down my results.

Updating the data becomes a bit tricky however. If one wants to stay away from comp keys then I would resort to some surrogate key mechanism. Each C would have it's own meaningless ID and be bound by an effective date range. This is where it's becoming sticky in my head. In actuality, each physical C is a version of a logical C. By logical I mean that if C were to represent a unique entity, say an Address of 123 Main St., Anywhere USA. When I introduce time effectiveness and change some property such as whether the address is a business or a residence I imagine I would create a new C (with a new ID) with a newly bound date range. In essence I now have 2 records that represent the same address.

Everything is still fine as long as the 2 Cs do not have an overlapping date effectiveness. However, if I may run into a situation where I say that a record is effective from Jan 1, 2004 to Dec 31, 2004. At some later date I say that from Feb 1, 2004 to Feb 15, 2004 there was some change to the record. I have a few possibilities at this point.

a)I try to time slice the existing record, terminating it. Then turn around and create a new record from Feb 1 - Feb 15 and then finally dump in yet another record from Feb 16-Dec 31 that mirrors the Jan 1 one. If you've followed that then you're probably saying, ick :)

b)Dump in a new record from Feb 1-Feb 15 with an addition create or update date and then when I encounter 2 (or more) overlapping records then I take the most recent.

I lean towards b as I think it lends itself to a lesser degree of hocus pocus when modifying records.

However, I believe that it becomes much more tangly if my 'B' is also time effective. If I simply create another B whenever I attempt to update one then I really need to copy/clone/insert your favorite term any associated records that are also valid for that particular timeframe. i.e. B has a a collection of Cs then each C should have a FK reference back to B. If I am inserting a fresh B then I will need to also insert fresh Cs that have a reference back to the newly inserted Bs.

This has the potential in my case to affect A LOT of records. However, this functionality that I am trying to implement should not be used that often therefore I am willing to take the hit of having to create this extra batch of data.

If I am manipulating the C objects directly it might not be that bad, however, with the event of cascades I am trying to find a slick method of flipping my UPDATES to INSERTS when I send the objects off to be persisted. I thought of using the unsaved-value='any' however that doesn't seem to work for a few reasons:
-I do have some comp keys in my system so I use an interceptor to call an isSaved() method. To get to the unsaved-value check I have to return null so that would require some manipulation for it in order to work.
-However, if I return NULL out of the interceptor and check the unsaved-value='any', during a cascade delete hibenate thinks that I have a transient object and rolls over.

So, in essence, for a hibernate solution I am looking for a 'good' way to implement this INSERTING rather than UPDATING behaviour for my time sensitive objects.

I think I can handle the selects, etc via the filtering mechanism (I hope), I'm just having a huge difficulty getting my head wrapped around actually maintaining the data and having it remain sane with the cascading. Worst case scenario I guess I would turn cascading off and handle it manually but that thought makes me cringe.


My 'other' option is to use Oracle's Workspace Manager Valid Time support. We've already opted to use the Workspace Manager in order to provide a working sandbox for the user to manipulate the data in a 'safe' environment, verify their changes, and then merge the data back in.

For those who are not at all familiar with it, the Valid Time support will essentially slice up your data based on VALID_FROM, VALID_TO columns that it adds to your tables and manages them internally. When you open a connection you can specify a valid time range and you will only see data that meets that criteria. It also handles the slicing and dicing of the records and converting the UPDATES to INSERTS.

In the beginning it looked like this was the silver bullet solution to my particular problem. However, in this scenario, what it does is take what you've defined as your PK and wrap it up in its own comp key. So in reality you can get multiple records of what you think is your PK. This is all fine as long as you don't get multiple records within the same time period.

I am thinking that if I had a many-to-one defined that said to load a 'B' with ID 5 and it found 2 of them, chaos would ensue.

Maybe I am over complicating this but if I am, someone please give me a slap and give me a nudge in the right direction will you? I am thinking that the solution that doesn't involve Oracle's valid time support would be cleaner in the sense that it doesn't further tie us to Oracle. But in reality, it doesn't matter as long as we can get it to work.

I'd love to hear any suggestions or experiences with any aspect of this. I need a fresh perspective and hopefully I can find some way to implement this relatively cleanly.


Top
 Profile  
 
 Post subject: any experience with the supposed solution
PostPosted: Sun Jul 10, 2005 4:16 pm 
Beginner
Beginner

Joined: Tue Nov 30, 2004 6:19 am
Posts: 29
Location: Germany
Hi,

I currently reached the same problem ... did you make some experiences with the described solution above?

My decission is to use the TemporalObjject Pattern desribed by Martin Fowler, but I'm quite unshure how to realize relations (1:n and 1:1) between these temporal Objects.
Based on http://www.martinfowler.com/ap2/temporalObject.html, I plan to have container ('Contract' in the example) and versions ('ContractVersion' in the example).
For a 1:1 relation between temporal objects A and B, I can see two posibilities:

    a) A.version will own the relation to B.container and B.version will own the relation to A.container
    b) I can use a seperate temporal relation object in between A and B


How have you solved these issues?
What's your experience?


Kind regards,
Michael


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 11, 2005 12:18 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Well jerger, we've adopted an approach that has worked very well for us so far.

We use the same patten as you're planning on using, i.e. Entity/EntityVersion.

The "Entity" table contains all the static type data, i.e. Primary Id of the Entity and anything else that is deemed not to change over time.

The EntityVersion table then contains all the time sensitive data. We ended up taking the approach of having overlapping entries, rather than trying to time slice. We use filtering to narrow down the results and then take the max created one if 2 exist in the same time period.

As far as relationships go, if it is a relation FROM a versioned entity and the relationship is time sensitive then it goes down on the version table, otherwise it is on the main Entity table.

As far as relationships TO a versioned entity they ALWAYS reference the main Primary Id of the entity. i.e. nothing ever references to the versioned table.

We then have Java objects that are responsible for spawning versions as applicable and they are mapped in hibernate as Sets (1 to many) coming off the main Entity Object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 10:28 am 
Beginner
Beginner

Joined: Tue Nov 30, 2004 6:19 am
Posts: 29
Location: Germany
Hi VampBoy,

thanks for your response :-) If I'm rigth, you've implemented my described solution a).
How is your experience with spawning objects?
Spawned versions is something I'm afraid of because that can lead to confusing situations (business changes on technical spawned versions) ... at least in my context

Kind regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 3:53 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Yes, I think A) would be correct.

We haven't had too many issues with the spawned versions except in the case where they get created too quickly, we need to change our CREATE_DATE to a Timestamp as if you create 2 versions in the same second things get dicey.

We treat spawning versions as such that a 'version' consists of any changes made in between saves. i.e. if I pull an object out of the DB and change 6 properties then save it then it is 1 version. However, if I save inbetween each change then it is 6 versions. (why anyone would do this in our case however....)

Our business case is a bit unique I would think though, as we have to support an amendment process wherin I can go back to a particular month (or day as well) and modify a versioned entity and the value is only in effect for that day. As opposed to when the users are working in LIVE data and the version is in effect until it is later changed. However, it is working very well for us for about 9 months or so now.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 4:37 pm 
Beginner
Beginner

Joined: Tue Nov 30, 2004 6:19 am
Posts: 29
Location: Germany
Do you have somthing like a leading TemporalObject which inherits his time period to the related 'child' TemporalObjects?
If I'm right, that's something what's missing on my business case.

Kind regards, Michael


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 10:26 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Maybe....

We have a "Versionable" super class that contains all of the version logic. We then use xdoclet in order to generate the appropriate filters, as they are all pretty much the same.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 7:05 am 
Beginner
Beginner

Joined: Tue Nov 30, 2004 6:19 am
Posts: 29
Location: Germany
we will try out your solution and in some months I can give back our experience :-)

By the way, wich version of xdoclet supports filters?
In the newest 1.2.3 I havn't found anything about filters ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 10:24 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
It doesn't, we modified the templates to do what we needed. We need to evaluate at some point whether or not annotations will work with what we've got.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 14, 2005 11:44 am 
Beginner
Beginner

Joined: Tue Nov 30, 2004 6:19 am
Posts: 29
Location: Germany
Your answer affirmed my fear ;)
Much thanx for your help :-))


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 21 posts ]  Go to page 1, 2  Next

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.