-->
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.  [ 4 posts ] 
Author Message
 Post subject: Querying separately versioned entities at a point in time.
PostPosted: Wed Apr 26, 2006 11:03 am 
Newbie

Joined: Tue Apr 25, 2006 10:34 pm
Posts: 3
Hi,
I am trying to create a new database where each entity is versioned. This means that I have an id(catalog number) for each entity that is constant over time. I also have an id for each version (serial number). Each version has two dates corresponding to validfrom/validto of that particular version. Each association between entities is hooked up by a foreign key reference to catalog number.

The application usage is to query all data that is valid at a particular point in time.

From an application writer point of view, I would like to use 1:1,1:N,N:1 to map all the relationships. It is just cleaner that way.

I took a look at filters and read many posts talking about why they don't/shouldn't correspond to the cardinality of an association. I don't necessarily disagree, but unfortunately it doesn't help solve this problem.

I took a look at the version column but that basically only seems used for concurrency purposes and doesn't really address query for particular versions.

Is there some way to parameterize some property across a graph query so that I can retrieve a snapshot of the object graph at a specified time?

I can think of several hard-coded ways to do this (like creating a mapping/view to the db with fixed points in time), but none of them seem to be the correct solution and effectively mean operational changes to keep the mappings/views up-to-date.

This problem is relevant for a new system I'm writing as well as reading data from a legacy system.

Here is a mapping file for two entities of the legacy system:

Code:
<hibernate-mapping default-access="field" package="com.ubs.eqdel.data.model.instance">

    <class name="Factor">
        <id name="id">
            <generator class="native"/>
        </id>
      <property name="catalog" column="catalog#"/>
        <property name="vol"/>
        <property name="factorIdentity"/>
        <property name="currency"/>
        <property name="size"/>
      <property name="validfrom_date"/>
      <property name="termination_date"/>
      <bag name="betas" mutable="false">
         <key column="factorID" property-ref="catalog"/>
         <one-to-many class="Beta"/>
         <filter name="validAtFilter"/>
      </bag>
      <filter name="validAtFilter"/>

    </class>

    <class name="Beta">
        <id name="id">
            <generator class="native"/>
        </id>
      <property name="catalog" column="catalog#"/>
        <property name="product"/>
        <property name="beta"/>
      <property name="validfrom_date"/>
      <property name="termination_date"/>

<!--
      <many-to-one name="factor" column="factorID" property-ref="catalog"/>
-->

      <filter name="validAtFilter"/>

   </class>

   <filter-def name="validAtFilter" condition="validfrom_date &lt;= :validAtDate AND termination_date &gt; :validAtDate">
      <filter-param name="validAtDate" type="timestamp"/>
   </filter-def>

</hibernate-mapping>



The above is an example where I tried using filters(notice how I had to disable the many-to-one because of the cardinality problems). I don't really care what the mechanism is, but some type of query-scoped parameterization seems like the right approach.

I'm using Hibernate version 3.1.

Any help would be appreciated.

Thanks,
Dave
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 12:06 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Sounds like a problem tailor-made to be solved by filters. Have a look at chapter 17 of the ref docs, "Filtering Data".


Top
 Profile  
 
 Post subject: Chapter 17
PostPosted: Thu Apr 27, 2006 7:01 am 
Newbie

Joined: Tue Apr 25, 2006 10:34 pm
Posts: 3
I already looked at Chapter 17. If filters attached to a class would be used when navigated to, that would be ideal. Does 3.1 have a bug that prevents this from working correctly?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 6:57 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not as far as I'm aware. I use them and they work. The class-level filter applies when you get instances using the class but not the ID, e.g. using HQL "from <class> where <non-id-param> = <value>" or Session.createCriteria(<class>).add(Restrictions.eq(<non-id-param>, <value>). The collection-level filtering applies when you navigate from a "parent" object.

Explicit fetches by ID (Session.get/load, non-collection associations from other objects) cannot be filtered: after all, that would "break" unfiltered objects. If an unfiltered parent object is associated with an object, then that object must be fetchable, as it's part of the parent's definition or contract. If a filter prevented that object from loading, then that parent object's definition would be wrong.

For example, consider a database in which every object is owned by a user, and when a user logs in they can only see objects that pass the "ownerid = :UserID" filter. If one object has the correct ownerid, then it must be loadable, even if it is associated with an object with the wrong ownerid. If such a situation arose, hibernate allows the bad object to be loaded. You should use business logic to prevent this situation from ever occurring, and maybe have check constraints in your database to back up the business logic.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.