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.  [ 4 posts ] 
Author Message
 Post subject: Filtered relationship to a joined-subclass doesn't work
PostPosted: Thu Jul 20, 2006 1:31 pm 
Newbie

Joined: Thu Jul 20, 2006 12:53 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

3.2 CR3

Mapping documents:

artifact.hbm.xml

Code:
<hibernate-mapping default-cascade="none">
    <class name="com.genologics.platform.model.processmanager.ArtifactImpl" table="artifact" dynamic-insert="false" dynamic-update="false">
        <cache usage="read-write" />
        <id name="artifactID" type="java.lang.Long">
            <column name="artifactID"/>
            <generator class="com.genologics.platform.objectmanagement.keygeneration.hibernate.GLSHibernateKeyGeneratorImpl">
            </generator>
        </id>
        </property>
      <property name="datastoreID" type="java.lang.Long">
            <column name="datastoreID" not-null="false" unique="false"/>
        </property>
        <property name="isGlobal" type="java.lang.Boolean">
            <column name="isGlobal" not-null="false" unique="false"/>
        </property>
        <filter name="datastore" condition="(datastoreID = 1 OR isGlobal)"/>
    </class>
</hibernate-mapping>


analyte.hbm.xml (child of artifact)

Code:
<hibernate-mapping default-cascade="none">
    <joined-subclass name="com.genologics.platform.model.processmanager.AnalyteImpl" extends="com.genologics.platform.model.processmanager.ArtifactImpl" table="analyte" dynamic-insert="false" dynamic-update="false">
        <key column="artifactID" />
        <property name="analyteID" type="java.lang.Long">
             <meta attribute="definition-pk-field">true</meta>
            <column name="analyteid" not-null="true" unique="true"/>
        </property>
        <property name="isCalibrant" type="java.lang.Boolean">
            <column name="iscalibrant" not-null="true" unique="false"/>
        </property>
        <set name="portions" order-by="portionid" lazy="true" fetch="select" inverse="true" cascade="delete-orphan">          
            <cache usage="read-write" />
            <key property-ref="analyteID" foreign-key="fk_portion_a">
                <column name="analyteid"/>
            </key>
            <one-to-many class="com.genologics.platform.model.processmanager.PortionImpl"/>       
            <filter name="datastore" condition="(datastoreID = 1 OR isGlobal)"/>
        </set>
    </joined-subclass>
</hibernate-mapping>


portion.hbm.xml (references analyte)

Code:
<hibernate-mapping default-cascade="none">
    <class name="com.genologics.platform.model.processmanager.PortionImpl" table="portion" dynamic-insert="false" dynamic-update="false" persister="com.genologics.platform.objectmanagement.hibernate.PortionEntityPersister">
        <cache usage="read-write" />
        <id name="portionID" type="java.lang.Long">
            <column name="portionid"/>
            <generator class="assigned">
            </generator>
        </id>
        <property name="datastoreID" type="java.lang.Long">
            <column name="datastoreID" not-null="false" unique="false"/>
        </property>
        <property name="isGlobal" type="java.lang.Boolean">
            <column name="isGlobal" not-null="false" unique="false"/>
        </property>
        <many-to-one name="analyte" class="com.genologics.platform.model.processmanager.AnalyteImpl" cascade="none" property-ref="analyteID" foreign-key="fk_portion_a" lazy="proxy" fetch="select">
            <column name="analyteid" not-null="false"/>
        </many-to-one>
        <filter name="datastore" condition="(datastoreID = 1 OR isGlobal)"/>
    </class>
</hibernate-mapping>


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

Using spring's hibernateTemplate

Full stack trace of any exception that occurs:

Code:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select count(distinct portionimp0_.portionid) as col_0_0_ from portion portionimp0_ inner join analyte analyteimp1_ on portionimp0_.analyteid=analyteimp1_.analyteid and (analyteimp1_1_.datastoreID = 1 OR analyteimp1_1_.isGlobal) inner join artifact analyteimp1_1_ on analyteimp1_.artifactID=analyteimp1_1_.artifactID where (portionimp0_.datastoreID = 1 OR portionimp0_.isGlobal) and analyteimp1_.iscalibrant=true]; nested exception is java.sql.SQLException: ERROR: relation "analyteimp1_1_" does not exist
java.sql.SQLException: ERROR: relation "analyteimp1_1_" does not exist
   at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1471)
   at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1256)
   at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:175)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:388)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:329)
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:239)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1695)
   at org.hibernate.loader.Loader.doQuery(Loader.java:662)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2172)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2056)
   at org.hibernate.loader.Loader.list(Loader.java:2051)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:396)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:852)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
   at org.springframework.orm.hibernate3.HibernateTemplate.findByNamedParam(HibernateTemplate.java:843)
   at com.genologics.platform.objectmanagement.HibernateProvider.findRootPojo(HibernateProvider.java:237)
   at com.genologics.platform.objectmanagement.HibernateProvider.find(HibernateProvider.java:107)
   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 $Proxy14.find(Unknown Source)
   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.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:165)


Name and version of the database you are using:

Postgresql 7.4.7

The generated SQL (show_sql=true):

Code:
select count(distinct portionimp0_.portionid) as col_0_0_
from portion portionimp0_
inner join analyte analyteimp1_ on portionimp0_.analyteid=analyteimp1_.analyteid and (analyteimp1_1_.datastoreID = 1 OR analyteimp1_1_.isGlobal)
inner join artifact analyteimp1_1_ on analyteimp1_.artifactID=analyteimp1_1_.artifactID
where (portionimp0_.datastoreID = 1 OR portionimp0_.isGlobal) and analyteimp1_.iscalibrant=true


Debug level Hibernate log excerpt:

n/a

Description:

The original HQL that produced the SQL:

Code:
SELECT COUNT(DISTINCT _PortionImpl0) FROM com.genologics.platform.model.processmanager.PortionImpl _PortionImpl0 JOIN _PortionImpl0.analyte _analyte0 WHERE _analyte0.isCalibrant = true


We're doing a query for Portion but joining to Analyte, which is mapped as a joined-subclass. There is a filter on this relationship. The problem is that the HQL->SQL translation does not create the joins correctly.

The joined-subclass join occurs after the filter is injected that refers to the joined-subclass join.

The joined-subclass join snippet:

Code:
inner join artifact analyteimp1_1_ on analyteimp1_.artifactID=analyteimp1_1_.artifactID


The filter that refers to the join:

Code:
(analyteimp1_1_.datastoreID = 1 OR analyteimp1_1_.isGlobal)


Looks like a bug to me? Can anyone suggest a workaround?

Thanks.


Top
 Profile  
 
 Post subject: Is there any solution?
PostPosted: Wed Oct 18, 2006 10:21 pm 
Newbie

Joined: Wed Oct 18, 2006 9:50 pm
Posts: 1
I have the same problem. After search "joined-subclass filter", there are several posts mentioned the same problem. But all posts seemed to got no answer. Anyone has a way to solve this problem?

Any kind of help is appreciated. Thank you very much.


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Tue Nov 14, 2006 5:06 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
I have the same problem with a very simply polymorphic query:
Code
Code:
public class A;
public class B extends A;
public class C extends B;

HQL
Code:
select count(*) from A as a where a.class = A

Error
Code:
Hibernate: select count(*) as col_0_0_ from A a0_ where case when a0_2_.A_ID is not null then 2 when a0_1_.A_ID is not null then 1 when a0_.A_ID is not null then 0 end=0
2006-11-14 14:58:14,873 DEBUG [com.mchange.v2.sql.SqlUtils] - Attempted to convert SQLException to SQLException. Leaving it alone. [SQLState: S0002; errorCode: 107]
com.microsoft.sqlserver.jdbc.SQLServerException: The column prefix 'a0_2_' does not match with a table name or alias name used in the query.
   at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
   at com.microsoft.sqlserver.jdbc.IOBuffer.processPackets(Unknown Source)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.sendExecute(Unknown Source)
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteQuery(Unknown Source)
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(Unknown Source)
   at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
   at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
   at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
   at org.hibernate.loader.Loader.doQuery(Loader.java:662)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:749)
   at com.nkics.socialworkprn.swan.test.persistence.GeneralTests.testCountQuery(GeneralTests.java:34)
   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 junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Top
 Profile  
 
 Post subject: accidental post. wish I could delete this...
PostPosted: Tue Nov 14, 2006 5:07 pm 
Beginner
Beginner

Joined: Mon Apr 24, 2006 9:47 pm
Posts: 33
Location: Kansas City, MO
accidental post. wish I could delete this...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.