-->
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.  [ 1 post ] 
Author Message
 Post subject: Historical snapshot classes
PostPosted: Thu Jun 04, 2009 1:03 pm 
Newbie

Joined: Thu Jun 04, 2009 12:21 pm
Posts: 2
I have designed a class which represents a historical snapshot of an employee, and I am trying to find the best way to map it. The intent of this class is to be able to retrieve various changing properties of an employee, given a retrieval date. The changing properties are spread across several tables, or are generated by procedures:
Code:
public class TransitoryEmployee implements Serializable {
  //the employee number and retrieval timestamp
  //are used to generate this object from the DB
  private int employeeNbr;
  private DateTime retrievalTmstp;
 
  private LocalDate hireDate;  //non-changing
  private LocalDate birthDate; //non-changing
  private int ageYearsAmt;     //generated
 
  private LocalDate seniorityDate; //tracked in a history table
  private CrewPosition crewPosition; //tracked in a history table
  private String payStatusCode; //tracked in a history table
 
  private int payRateCentsAmt; //hourly pay rate in cents, generated by procedure
...
}


There is no database table that this class can be mapped to; it is read-only by nature. I have written a single query which can populate this class, and takes the arguments employeeNbr and retrievalTmstp.

How can I incorporate this query into a hibernate mapping file? I am considering two options right now, but would appreciate other ideas.

Option 1. Write a mapping file with a composite ID of employeeNbr and retrievalTmstp, using a native SQL query as a loader. This feels unnatural, and I've encountered lots of problems attempting to implement it.

Option 2. Use filters, similar to the example from section 17 of the Hibernate documentation. However, I am not sure how to make this work. A filter would need to be applied for the retrieval timestamp, but this class can not be created in absence of a filter. Can Hibernate force a filter to be used? Also, when using the filter, how can the object field retrievalTmstp be populated using the value being passed to the filter?

Are either or these options practical? Is the whole idea of a historical snapshot class a bad idea? I'd love to get some input from somebody who has done something similar to this before.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.