-->
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: HQL -> SQL issues migrating from Hibernate 3.2.4 to 4.1.7
PostPosted: Sun Nov 11, 2012 8:39 pm 
Newbie

Joined: Sun Nov 11, 2012 7:48 pm
Posts: 1
Hi,

We are trying to migrate Hibernate from version 3.2.4 to 4.1.7 and we are facing some issues due to the way HQL is transformed to SQL. It happens whenever developers decide to mix explicit with implicit joins (we know it is not a good practice to mix these two strategies, but we have a whole ERP develop this way :-( ).

Let me show an example:

Code:
from A a
left join fetch a.b b_alias
where a.b.name = :param


For the above HQL, hibernate 3.2.4 generates the following SQL:

Code:
select
   a0_.id as id4_0_,
   b1_.id as id5_1_,
   a0_.b_id as b3_4_0_,
   a0_.name as name4_0_,
   b1_.name as name5_1_
from
   A a0_
left join
   B b1_
      on a0_.b_id=b1_.id
where
   b1_.name='entity_B'


It is ease to note that this hibernate's version actually tries to infers that the explicit join (i.e. left join fetch a.b b_alias) is the "same" that implicit one (i.e. a.b.name). Although we think it was an incorrect strategy to follow (once we have two different joins -- one left join and one inner join -- and hibernate merged it into only one left join), we could not change this hibernate behavior. Moreover, I don't think our developers have ever thought it would be changed some day.

In other way, if you run the same HQL in Hibernate 4.1.7, you will see that it is generating a completely different SQL.

Code:
Select
   a0_.id as id0_0_,
   b1_.id as id1_1_,
   a0_.b_id as b3_0_0_,
   a0_.name as name0_0_,
   b1_.name as name1_1_
from
   A a0_
left join
   B b1_
      on a0_.b_id=b1_.id
cross join
   B b2_
where
   a0_.b_id=b2_.id
   and b2_.name='entity_B'


In this case the new version of hibernate is trying to infer nothing. Once developer have added two joins (one for the explicit join and another for the implicit join), as expected, hibernate generates two joins. Although we think this solution is more correct than the one provided in Hibernate 3.2.4, it is making our migration extremely painful (to not say nonviable).

So the question is: is there any configuration or change we could do to make the the query interpreter to behave like the legacy Hibernate 3.2.4? or the only way will be to review and "rewrite" every query in the system? We have also thought to make a "hack" to intercept the HQL and parse it in order to keep our current behavior. What do you think about this solution? There exists a simple way to do this?

Any help will be appreciated
Thanks in advance


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.