views:

42

answers:

1

Hello,

I'm writing an HQL query, in the form of:

from a where ... or exists (from b inner join b.c where ...) and ...

I get back an entity of type a from this query. However, I need to also know whether the exists clause came back true or not later on in my code. If this was SQL, I'd tack it onto the select list. However, even if I add to the HQL select clause, so that it becomes:

select a, exists (from b inner join b.c where ...) as x from a where ... or x and ...

In my code I now have to choose between viewing untyped data, or viewing typed entities of type a and throwing away my value x that came back with it.

Is there a way to somehow get back typed data plus the extra column?

+2  A: 

You have two options here as I see it:

1) Add the additional property as a read-only mapped property to your entity, making use of the formula mapping to derive the value using inline sql or a udf.

2) Get only the data you need back using a custom hql query and use the aliastobeanresulttransformer to project to a strongly-typed dto that includes your fields of interest.

Which route you go is really up to you, but I'd tend to lean towards option #2 so as not to pollute your domain model with unneeded fields.

DanP
I went the `aliastobeanresulttransformer` route. However, I need to use a user type (IUserType) to map one of the columns. Is there a way to do this?
David Pfeffer
It should work seamlessly; just select the IUserType-dependant property using hql; it should be processed as if you were selecting a regular entity.
DanP