-->
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: How to use Derived Business Logic Properties in HQL Query
PostPosted: Mon Feb 13, 2006 6:31 pm 
Newbie

Joined: Fri Sep 03, 2004 3:12 am
Posts: 3
Hey,

Can anyone shed some light on how to use business logic Properties in a HQL Query.

Example

Code:
Car Object
    Color Property             (.hbm mapped)
    PlateNumber Property  (.hbm mapped)
    State Property             (Derived Business Logic Property)


The first two properties are simply table field lookups however the State Property is not mapped in the .hbm file it is instead a container for derived logic. Depending on the first 2 numbers of the PlateNumber determines the state that it comes from. (forgive the bad example, state should be stored on create)

What I want to achieve is to be able to use the State Property in a HQL Query for example.

Code:
From Car c where c.State = 'AK'


NHibernate doesn't seem to like this as State is not a mapped attribute. I can understand why this is the case as this can not be converted in to a SQL query of any type but would be might useful in attempting to better centralize business logic in model objects.

Can someone please advise?

Thanks, Adam


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 7:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You could map State using <property formula="yourformula"/>, moving the derivation of its value into the Hibernate layer. This would make it accessible from HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 7:54 pm 
Newbie

Joined: Fri Sep 03, 2004 3:12 am
Posts: 3
Thanks for the reply.

This could solve the problem I guess however I want to keep the business logic in the Business Tier and out of the Data Tier.

Ideally NHibernate would be able to post process business rules after queries have been executed. This presumably would cause a problem for aggregated queries.

Maybe I ask too much :(


Top
 Profile  
 
 Post subject: Try Custom UserType
PostPosted: Mon Feb 13, 2006 11:59 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
Have you tried using a Custom UserType.
I am not sure how do you want to use it in a HQL query when it is not mapped to a table column.


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.