-->
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: Formula on a many-to-one
PostPosted: Sun Jul 01, 2007 6:49 am 
Newbie

Joined: Fri Nov 17, 2006 9:40 am
Posts: 11
Location: Switzerland
Hi all

I've got a strictly Hibernate-related problem, but am still posting here as response is usually MUCH better! I've got an entity PARTICIPANT with a property birthyear, and an entity CATEGORY with a property age. Participants now have categories assigned according to the following business rules:
  • If exists calculateAgeFrom(PARTICIPANT.birthyear) == CATEGORY.age, participant.category is that category
  • If calculateAgeFrom(PARTICIPANT.birthyear) > max(CATEGORY.age), participant.category is NULL
  • If calculateAgeFrom(PARTICIPANT.birthyear) < min(CATEGORY.age), participant.category is that category which has the min(age)


Categories have age 15 to 20. If a participant has birthyear 1980, he's got no category (NULL), birthyear 1990 gets category with age 17, birthyear 1997 gets category with age 15 (min).

I can easily implement such a getCategory() rule in a service layer, but using Hibernate formulas would give me the huge advantage (I believe) of having the correct category directly available in a JasperReport (HQL-based).

Code:
<many-to-one name="category" class="ch.want.jtrack.model.Category" fetch="select">
   <formula>(select c from Category where age = (YEAR() - p.birthyear)</formula>
</many-to-one>


My participant.category property is transient and read-only (i.e. never persisted, always derived from birthyear), so I'd like something like the statement above, which fails. Can anyone help? I've seen the Hibernate tutorial on formulas, but I feel the scenario above is not covered.

Thanks a lot
Simon


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