-->
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: inheritance mapping - BUG?
PostPosted: Wed Oct 31, 2012 4:52 am 
Newbie

Joined: Wed Oct 31, 2012 4:31 am
Posts: 1
Hi I have this situation (using last Hibernate 4.1.7 Final version):
I have Order class, when have association to Client class, Client have to childrens Person and Company, both extending Client.
Person have associated PersonData when I have some more informations about Person (historization is needed). Similar Company have associated CompanyData. Tables are created what objects by per subclass mapping.

Now I want select orders by some kriteria, a then get Client, but only Person type and then his actualData (PersonData).

My select looks that (projection need some data from "PersonData", but first I trying generate correct joins) :
Code:
String par = "8%";
ProjectionList pl = Projections.projectionList();
      pl.add(Projections.property("order.id"), "orderId");
      pl.add(Projections.property("order.bookingsCode"), "bookingsCode");
      pl.add(Projections.property("order.client"), "person");
DetachedCriteria cr = DetachedCriteria
            .forClass(Order.class, "order")
            .createAlias("order.client", "person", JoinType.INNER_JOIN,
                  Restrictions.eq("class", Person.class))
            .createAlias("person.activeData", "adata")
            .add(Restrictions.like("order.bookingsCode", par)).setProjection(pl)
            .setResultTransformer(Transformers.aliasToBean(OrderView.class));


Interesant is what select that generate:
Code:
select
        this_.idBook_order as y0_,
        this_.bookings_code as y1_,
        this_.idClient as y2_
    from
        book_order this_
    inner join
        crm_contact person1_
            on this_.idClient=person1_.idCrm_contact
            and (
                person1_.type=?
            )
    inner join
        crm_companyData adata2_
            on person1_.idData=adata2_.idCrm_company
    inner join
        crm_personData adata2_
            on person1_.idData=adata2_.idCrm_personData
    where
        this_.bookings_code like ?


and ofc I got error (database is MySQL):
Code:
org.hibernate.exception.SQLGrammarException: Not unique table/alias: 'adata2_'


Error is corect hibernate generate two inner joins with same alias. My questions are
1. I don't want that code in my select:
Quote:
inner join
crm_companyData adata2_
on person1_.idData=adata2_.idCrm_company

2. it's probably BUG when hibernate using same alias in 2 joins

thx any1 who will be help


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.