-->
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.  [ 2 posts ] 
Author Message
 Post subject: Dynamic Filter Clarification and a "Can this be done?&q
PostPosted: Mon Oct 04, 2004 11:39 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Can someone clarify something for me? For some reason I had the impression that the Filter conditions were an HQL fragment yet it would appear that as I look at some more examples that it would be a SQL fragment? However, I believe I have seen some conflicting examples. For example, in the Reference doc the fragment references the column names rather than the property names suggesting SQL however I'm sure I've seen some that do things such as this.propertyName = 'bleh'.

If it is actually a SQL fragment then would the following be doable? I've got an instance where I may have multiple versions of a record due to an effective date strategy. The multiple records will have the same business key and what I want to find is the most current effective record.

The structure is essentially I have a 'header' table that contains the static data, i.e. Primary Key and other things that don't change over time.

Hanging off the 'header' is a version table that contains it's own PK, a FK back to the header table, a date range and any temporal properties.

Our code is doing filtering like this on the java side however, I'm thinking we'll need to filter on the db side since if a property HAD a value of 'X' at one point and is now 'Y' I don't want to return the record if someone searches on 'X'. i.e. I want to find a header record where a temporal property is a certain value at a certain point in time.

If I were to write the SQL to handle the version filtering it would look something like this:

Code:
select * from version a where create_date = (select max(create_date) from version b where a.business_id = b.business_id)


My next step will be to shoehorn hib 3 into the mix and try it out but if someone has a heads up that it may or may not work it might save me some head scratching :)

Also, I'm assuming that if I do this subquery then I'll need to do a filter for every header/version table combo that I have? It would be fantastic if I could define a generic filter for all of my combos as my filter criteria will be the same across the board, just the names of the tables will change.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 14, 2004 6:38 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Well, we've finally got around to the shoehorning and answered some of our own questions ;)

However, to help any other poor souls out there...


It IS indeed a SQL fragment. Either I've seen invalid examples or I'm on dope (50/50 chance)

Subqueries DO work however you can't use the table name as a parameter since it translates the filter into a PreparedStatement and the PS doesn't support that. (consider maybe something that would do simple String substitution?)

Either way, it looks like we're going to try to get around the dynamic table name 'issue' by some Xdoclet magic since we'll know the table name at xml generation time.

Again the reason we wanted to do this was that we have a common db pattern for our temporal data and want to be apply to write generic filters as they'll essentially all be the same.


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