-->
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: Duplicate column aliases with ternary associations
PostPosted: Wed Jan 04, 2006 2:02 pm 
Newbie

Joined: Wed Jan 04, 2006 12:52 pm
Posts: 4
When trying to eagerly fetch a ternary association (mapped as suggested in Hibernate in Action), we are seeing multiple column aliases in the generated SQL. Sybase does not tolerate these, and even our dummy HSQLDB instances seem to have problems when the number of replicates gets high, silently failing with zero rows returned. The example provided below produces incorrect results on both HSQLDB and Sybase with 4 of the same sets of column aliases.

This does not appear to have been a problem with the more recent Hibernate 2.x releases. Hibernate 3.x releases other then 3.1 final will attempt to execute the SQL with the multiple column aliases, but 3.1 final throws a NullPointerException with a stack trace that appears to be identical to that documented in JIRA issue HHH-1306

Hibernate version: 3.0, 3.1

Mapping documents:

Ternary association mapping portion of ArrayPrintSession.hbm.xml:

Code:
      <set
         name="workers"
         table="z_arrprntsess_wrkr_x"
         cascade="all">
         <key column="arr_prnt_sess_id" />
         <composite-element
            class="org.pfgrc.microarray.ArrayPrintSessionWorker">
            <meta attribute="implement-equals">true</meta>
            <parent name="printSession" />
            <many-to-one
               name="login"
               class="org.pfgrc.microarray.Login"
               column="login_id">
               <meta attribute="use-in-equals">true</meta>
            </many-to-one>
            <many-to-one
               name="duty"
               class="org.pfgrc.microarray.ArrayPrintSessionDuty"
               column="arr_prnt_sess_duty_cd">
               <meta attribute="use-in-equals">true</meta>
            </many-to-one>
         </composite-element>
      </set>



Code between sessionFactory.openSession() and session.close():

Code:
            Session session = SessionFactoryUtils.getSession(this
                    .getSessionFactory(), false);

            String qtxt;

            qtxt = "select ps from ArrayPrintSession ps "
                    + "left join fetch ps.slideType "
                    + "left join fetch ps.machine "
                    + "left join fetch ps.status "
                    + "left join fetch ps.workers "
                    + "left join fetch ps.slides slide "
                    + "left join fetch slide.status "
                    + "where ps.description = :description";

            Query query = session.createQuery(qtxt);
            query.setString("description", name);
            ArrayPrintSession ret = (ArrayPrintSession) query.uniqueResult();




Full stack trace of any exception that occurs:

This occurs only with 3.1 final. 3.1 rc3 and 3.0.5 generate the duplicate aliases, but not the NullPointerException.

Code:
java.lang.NullPointerException
     at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:175)
     at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:637)
     at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:466)
     at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:643)
     at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:279)
     at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:227)
     at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
     at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
     at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:105)
     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:74)
     at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:53)
     at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
     at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:108)
     at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:88)
     at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1540)
     at org.pfgrc.microarray.dao.hibernate.ArrayPrintSessionHibernateDao.loadArrayPrintSessionForCreateTest(ArrayPrintSessionHibernateDao.java:364)
     at org.pfgrc.microarray.business.printing.MAPrintingBusObj.loadArrayPrintSessionForCreateTest(MAPrintingBusObj.java:205)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:585)
     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
     at $Proxy6.loadArrayPrintSessionForCreateTest(Unknown Source)
     at test.org.pfgrc.microarray.system.create.CreatePrintSessionTest.testThis(CreatePrintSessionTest.java:40)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:585)
     at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:435)
     at org.testng.internal.Invoker.invokeMethod(Invoker.java:356)
     at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:523)
     at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:89)
     at org.testng.TestRunner.privateRun(TestRunner.java:622)
     at org.testng.TestRunner.run(TestRunner.java:505)
     at org.testng.SuiteRunner.privateRun(SuiteRunner.java:200)
     at org.testng.SuiteRunner.run(SuiteRunner.java:126)
     at org.testng.TestNG.run(TestNG.java:285)
     at org.testng.TestNG.privateMain(TestNG.java:372)
     at org.testng.TestNG.main(TestNG.java:321)



Name and version of the database you are using:

Sybase Adaptive Server Enterprise/12.5.3/EBF 12876 ESD#4/P/Linux Intel/Enterprise
Linux/ase1253/1923/32-bit/OPT/Thu Sep 8 06:16:18 2005

HSQLDB 1.8.0.2


The generated SQL (show_sql=true):

I've done a little formatting of whitespace here, otherwise this should be identical to what Hibernate outputs. Note that the triplet of workers4_ columns appears four times:

Code:
select
arrayprint0_.arr_prnt_sess_id as arr1_0_,
slidetype1_.slide_type_id as slide1_1_,
arrayprint2_.arr_prnt_mach_id as arr1_2_,
arrayprint3_.arr_prnt_sess_stat_cd as arr1_3_,
slides5_.slide_id as slide1_4_,
slidestatu6_.slide_qc_cd as slide1_5_,
arrayprint0_.session_dt as session2_43_0_,
arrayprint0_.machine_cycles as machine3_43_0_,
arrayprint0_.pen_id as pen4_43_0_,
arrayprint0_.pen_cycles as pen5_43_0_,
arrayprint0_.humidity_control as humidity6_43_0_,
arrayprint0_.humidity_set_point as humidity7_43_0_,
arrayprint0_.arbor_id as arbor8_43_0_,
arrayprint0_.file_name as file9_43_0_,
arrayprint0_.is_crosslinked as is10_43_0_,
arrayprint0_.arr_prnt_sess_dscr as arr11_43_0_,
arrayprint0_.comments as comments43_0_,
arrayprint0_.num_plates_entered as num13_43_0_,
arrayprint0_.slide_type_id as slide14_43_0_,
arrayprint0_.arr_prnt_sess_stat_cd as arr15_43_0_,
arrayprint0_.arr_prnt_mach_id as arr16_43_0_,
workers4_.arr_prnt_sess_id as arr1_0__,
workers4_.login_id as login2_0__,
workers4_.arr_prnt_sess_duty_cd as arr3_0__,
slidetype1_.slide_type_nam as slide2_54_1_,
slidetype1_.slide_type_dscr as slide3_54_1_,
slidetype1_.is_active as is4_54_1_,
slidetype1_.arr_prnt_mach_typ_cd as arr5_54_1_,
slidetype1_.arr_prnt_protcl_id as arr6_54_1_,
slidetype1_.buffer_typ_cd as buffer7_54_1_,
workers4_.arr_prnt_sess_id as arr1_0__,
workers4_.login_id as login2_0__,
workers4_.arr_prnt_sess_duty_cd as arr3_0__,
arrayprint2_.arr_prnt_mach_typ_cd as arr2_41_2_,
arrayprint2_.arr_prnt_mach_nam as arr3_41_2_,
arrayprint2_.internal_machine_id as internal4_41_2_,
arrayprint2_.arr_prnt_mach_dscr as arr5_41_2_,
arrayprint2_.is_default as is6_41_2_,
arrayprint2_.is_active as is7_41_2_,
arrayprint2_.sort_order as sort8_41_2_,
arrayprint2_.arr_prnt_mach_typ_cd as arr2_2_,
workers4_.arr_prnt_sess_id as arr1_0__,
workers4_.login_id as login2_0__,
workers4_.arr_prnt_sess_duty_cd as arr3_0__,
arrayprint3_.arr_prnt_sess_stat_cd_dscr as arr2_58_3_,
arrayprint3_.is_default as is3_58_3_,
arrayprint3_.is_active as is4_58_3_,
arrayprint3_.sort_order as sort5_58_3_,
workers4_.arr_prnt_sess_id as arr1_0__,
workers4_.login_id as login2_0__,
workers4_.arr_prnt_sess_duty_cd as arr3_0__,
slides5_.slide_barcode as slide2_53_4_,
slides5_.mfg_lot_no as mfg3_53_4_,
slides5_.print_order as print4_53_4_,
slides5_.arr_prnt_sess_id as arr5_53_4_,
slides5_.mfg_slide_typ_cd as mfg6_53_4_,
slides5_.slide_qc_cd as slide7_53_4_,
slides5_.arr_prnt_sess_id as arr5_1__,
slides5_.slide_id as slide1_1__,
slidestatu6_.slide_qc_cd_dscr as slide2_60_5_
from z_arr_prnt_sesss arrayprint0_
left outer join z_slide_types slidetype1_ on arrayprint0_.slide_type_id=slidetype1_.slide_type_id
left outer join z_arr_prnt_machs arrayprint2_ on arrayprint0_.arr_prnt_mach_id=arrayprint2_.arr_prnt_mach_id
left outer join z_arr_prnt_sess_stat_cds arrayprint3_ on arrayprint0_.arr_prnt_sess_stat_cd=arrayprint3_.arr_prnt_sess_stat_cd
left outer join z_arrprntsess_wrkr_x workers4_ on arrayprint0_.arr_prnt_sess_id=workers4_.arr_prnt_sess_id
left outer join z_slides slides5_ on arrayprint0_.arr_prnt_sess_id=slides5_.arr_prnt_sess_id
left outer join z_slide_qc_cds slidestatu6_ on slides5_.slide_qc_cd=slidestatu6_.slide_qc_cd
where
arrayprint0_.arr_prnt_sess_dscr=?


Debug level Hibernate log excerpt:

There's a lot of output here, not sure what might be relevant. This can be provided upon request.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 5:55 pm 
Newbie

Joined: Wed Jan 04, 2006 12:52 pm
Posts: 4
A minor correction to my original post: it turns out that HSQLDB does not have a problem with these duplicate aliases. The problem with HSQLDB in this case was completely unrelated to the duplicate aliases. Sybase continues to be intolerant of any number of duplicate aliases.


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.