Hi and thank you all for quick answers.
I'm sorry I reply so late but I didn't get any email from nhusers in
the last couple of days, like it wasn't any activity on the group,
dunno why... It seems to work again after I chaged my user settings.

Anyway, I'll try to be as brief as possible.
I don't have a specific set of mappings because I'm envolved in a
project that implies generating classes/mappings/tables given a custom
sort of DSL (a  model) that I don't control. In certain scenarios I
use table per concrete class strategy. All of those work pretty well
and a generated mapping for this strategy looks very much similar to
the ones in your example:

<class name="Payment">
        <id name="Id" type="Int64" column="PAYMENT_ID">
                <generator class="sequence"/>
        </id>
        <property name="Amount" column="AMOUNT"/>
                ...
        <union-subclass name="CreditCardPayment"
table="CREDIT_PAYMENT">
                <property name="CreditCardType" column="CCTYPE"/>
                ...
        </union-subclass>
        <union-subclass name="CashPayment" table="CASH_PAYMENT">
                              <property name="ReceiptNo"
column="RECEIPTNO"/>
                ...
        </union-subclass>
        <union-subclass name="ChequePayment" table="CHEQUE_PAYMENT">
                ...
        </union-subclass>
</class>

Now, a part of our DSL is a custom query language used for reporting
that I transform to HQL - save the HQL to DB and run it with the
report later on.  This means that basically I'm constrained to use
only HQL and not Criteria or linq.
The result is always a projection and I use left join wherever 2
entiites are associated e.g if I would have a FinancialTransacton
class that has a Payments property of type IList<Payment>
 select fin.Description, p.Amount
from FinancialTransaction fin left join fin.Payments p
where ... -> and here starts my problem :)

How can I write my HQL to restrict the results , for example, to only
those payments that are credit card payments of a specified type OR
Cash payments with a specified receiptNo?
(smth like: where (fin.Payments.class = "..CreditCardType..." and
p.CreditCardType = "Visa") or ( (fin.Payments.class =
"..CashPayment..." and p.ReceiptNo= "Visa") ))

Thanks




On Mar 10, 4:21 pm, Fabio Maulo <[email protected]> wrote:
> I'm asking mappings because with table-per-concreteclass mapped through
> <union-subclass> with HQL and with Criteria you have nothing to do, every
> thing is done by NH.
>
> 2010/3/10 Fabio Maulo <[email protected]>
>
>
>
>
>
> > mapping please
>
> > 2010/3/10 DanV <[email protected]>
>
> > Hi guys,
>
> >> I have a similar problem but I need to do it with HQL. Any idea how to
> >> do it, or if it is possible?
>
> >> On Mar 8, 6:58 pm, Diego Mijelshon <[email protected]> wrote:
> >> > As you may have guessed, you can't use polymorphic queries for
> >> properties
> >> > that are only defined in one of the classes.
> >> > If you desperately needed to make this one query, you could hack some
> >> > complex criteria with subqueries, or just write a SQL query with UNION.
> >> > However, it's probably cleaner to do it with two queries and join them
> >> with
> >> > LINQ-to-objects.
> >> > Since the Criteria API is actually more useful for search (where the
> >> > parameters vary), and you seem to have a pretty static query here, I'd
> >> go
> >> > one step further and use also NHibernate.Linq (you could also use
> >> QueryOver
> >> > with NH 3.x)
> >> > So, your whole query would be:
>
> >> > var listOfReservables = Session.Linq<FrameworkContract>().Where(fc =>
> >> > fc.Quantity > 0 && fc.Status == "Confirmed")
> >> >                                   .ToList().Cast<Reservable>()
> >> >                                   .Concat(
>
> >> Session.Linq<InventoryStock>().Where(fc =>
> >> > fc.Quantity > 0)
> >> >                                   .ToList().ToList().Cast<Reservable>())
>
> >> >    Diego
>
> >> > On Mon, Mar 8, 2010 at 13:13, Patrik Lowendahl
> >> > <[email protected]>wrote:
>
> >> > > Hello,
>
> >> > > I have a scenario where I fetch data from two different tables into a
> >> > > "Reservable". You can reserve from inventory stock or from framework
> >> > > contracts. This is mapped using Table per concrete class strategies.
> >> > > However, I found a challenge. There is slighty different rules in
> >> what's
> >> > > acceptable as a reservable. StockInventory it's sufficient with
> >> quantity > 0
> >> > > but for framework contracts it need to be cofirmed as well.
>
> >> > > I would like to do something like:
>
> >> > > var listOfReservables = Session.CreateCriteria(typeof (Reservable))
> >> > >       .Add(Restrictions.Gt("Quantity", 0))
> >> > >       .Add(Restrictions.Eq("Status", "Confirmed"))
> >> > >       .List<Reservable>();
>
> >> > > But this isn't possible in it's current form since StockInventory
> >> doesn't
> >> > > have a Status, just the Framework Contract. Is this possible? Or do I
> >> need
> >> > > to create two separate queries for each concrete class and joint them
> >> > > myself?
>
> >> > > --
> >> > > Patrik Löwendhl
>
> >> > > --
> >> > > You received this message because you are subscribed to the Google
> >> Groups
> >> > > "nhusers" group.
> >> > > To post to this group, send email to [email protected].
> >> > > To unsubscribe from this group, send email to
> >> > > [email protected]<nhusers%[email protected]­>
> >> <nhusers%[email protected]<nhusers%252bunsubscr...@googlegroup­s.com>
> >> ­>
> >> > > .
> >> > > For more options, visit this group at
> >> > >http://groups.google.com/group/nhusers?hl=en.-Hide quoted text -
>
> >> > - Show quoted text -
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "nhusers" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected]<nhusers%[email protected]­>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/nhusers?hl=en.
>
> > --
> > Fabio Maulo
>
> --
> Fabio Maulo- Hide quoted text -
>
> - Show quoted text -

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to