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: Parsing formula for computed property
PostPosted: Fri Oct 13, 2006 3:34 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
I have a question about formulas. Here is some context: part of my model looks like this:

Trial (1) --> (n) ExperimentalUnit (1) --> (n) Observation

It is an important state of a trial whether is has observations or not, i.e. is there any ExperimentalUnit with any Observation? I hate redundant state fields, so I want to determine this at runtime. However, when loading a list of trials it is a complete overkill to run through their ExperimentalUnit collections and Observation collections of each ExperimentalUnit until one is found with a count > 0. So I wanted to give my Trial a property with a formula like:

Code:
<property
   name="HasAnyObservation"
   formula="( select 1 from Trial trl where trl.TrlId = TrlId and (exists (select 1 from ExperimentalUnit eu where eu.TrlId = TrlId and (exists (select 1 from Observation obs where obs.ExpId = eu.ExpId)))) )"
   type="String"
/>


It appears that I am stretching NHibernate beyond its limits here. The generated query is:

SELECT trials0_.TrlId as TrlId__, ... , ( select 1 from Trial trl where trl.TrlId = trials0_.TrlId and trials0_.exists (select 1 from ExperimentalUnit eu where eu.TrlId = trials0_.TrlId and trials0_.exists (select 1 from Observation obs where obs.ExpId = eu.ExpId)) ) as f2_0_ FROM Trial trials0_ WHERE trials0_.CrpId=@p0

As you see, the 'exists' is seen as a field name and the query is nonsense.
I discovered that someone had found a similar issue before , here, and proposed a solution. Is there any chance that the potentially powerful formula feature will be 'fixed' to accomodate this kind of usage?


Top
 Profile  
 
 Post subject: Re: Parsing formula for computed property
PostPosted: Wed Oct 18, 2006 5:56 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
Since nobody answered and one of my collegues has a lazy=false setting :) we found out that it is actually possible to add keywords to the class that generates a query template for formula properties. This class puts an alias before about everything that is not in its keyword list. adding keywords should be done before the NHibernate is configured. We added:


Code:
using NHibernate.SqlCommand;

...

Template.AddKeyword("exists");
Template.AddKeyword("join");
Template.AddKeyword("inner");
Template.AddKeyword("outer");
Template.AddKeyword("left");
Template.AddKeyword("right");
Template.AddKeyword("on");


Just before Configuration.AddAssembly(...) is executed and voila, the query is kept intact!


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.