Tried to rewrite the query inline in the JavaCode instead of in the mapping file:
Code:
String queryString = "SELECT DISTINCT itemtocontentgroup.icg_sid as {itcg.itemToContentGroupId}, itemtocontentgroup.icg_position as {itcg.position}, " +
"item.itm_sid as {itcg.itemId}, item.itm_orderid as {itcg.itemOrderId}, item.itm_masterorderid as {itcg.itemMasterOrderId}, item.itm_name2 as {itcg.artist}, " +
"item.itm_name1 as {itcg.title}, item.itm_updatedate, contentgroup.ctg_sid as {itcg.contentGroupId}, contenttype.cty_key as {itcg.contentTypeKey}, " +
"contenttype.cty_name as {itcg.contentTypeName}, contentimport.cti_importdate as {itcg.contentImportDate}, " +
"(SELECT SUM(imc_counter) " +
"FROM itemcounter " +
"WHERE itemcounter.itm_sid2 = item.itm_sid " +
"AND imc_date > current_date - 7) AS {itcg.downloads7}, " +
"(SELECT SUM(imc_counter) " +
"FROM itemcounter " +
"WHERE itemcounter.itm_sid2 = item.itm_sid " +
"AND imc_date > current_date - 30) AS {itcg.downloads30}, " +
"(SELECT SUM(imc_counter) " +
"FROM itemcounter " +
"WHERE itemcounter.itm_sid2 = item.itm_sid " +
"AND imc_date > current_date - 90) AS {itcg.downloads90} " +
"FROM itemtocontentgroup " +
"JOIN item ON item.itm_sid = itemtocontentgroup.itm_sid " +
"JOIN contentimport ON item.cti_sid = contentimport.cti_sid " +
"JOIN contentgroup ON contentgroup.ctg_sid = itemtocontentgroup.ctg_sid " +
"JOIN contenttype ON contentgroup.cty_sid = contenttype.cty_sid " +
"WHERE itemtocontentgroup.ctg_sid=:contentGroupId " +
"ORDER BY " + orderByQueryString;
Query q = session.createSQLQuery(queryString).addEntity("itcg", ItemToContentGroupExtended.class);
q.setLong("contentGroupId", contentGroupId);
Now I'm getting the following exception message:
Code:
org.springframework.orm.hibernate3.HibernateQueryException: No column name found for property [itemMasterOrderId] for alias [itcg] [SELECT DISTINCT itemtocontentgroup.icg_sid as {itcg.itemToContentGroupId}, itemtocontentgroup.icg_position as {itcg.position}, item.itm_sid as {itcg.itemId}, item.itm_orderid as {itcg.itemOrderId}, item.itm_masterorderid as {itcg.itemMasterOrderId}, item.itm_name2 as {itcg.artist}, item.itm_name1 as {itcg.title}, item.itm_updatedate, contentgroup.ctg_sid as {itcg.contentGroupId}, contenttype.cty_key as {itcg.contentTypeKey}, contenttype.cty_name as {itcg.contentTypeName}, contentimport.cti_importdate as {itcg.contentImportDate}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 7) AS {itcg.downloads7}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 30) AS {itcg.downloads30}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 90) AS {itcg.downloads90} FROM itemtocontentgroup JOIN item ON item.itm_sid = itemtocontentgroup.itm_sid JOIN contentimport ON item.cti_sid = contentimport.cti_sid JOIN contentgroup ON contentgroup.ctg_sid = itemtocontentgroup.ctg_sid JOIN contenttype ON contentgroup.cty_sid = contenttype.cty_sid WHERE itemtocontentgroup.ctg_sid=:contentGroupId ORDER BY downloads90]; nested exception is org.hibernate.QueryException: No column name found for property [itemMasterOrderId] for alias [itcg] [SELECT DISTINCT itemtocontentgroup.icg_sid as {itcg.itemToContentGroupId}, itemtocontentgroup.icg_position as {itcg.position}, item.itm_sid as {itcg.itemId}, item.itm_orderid as {itcg.itemOrderId}, item.itm_masterorderid as {itcg.itemMasterOrderId}, item.itm_name2 as {itcg.artist}, item.itm_name1 as {itcg.title}, item.itm_updatedate, contentgroup.ctg_sid as {itcg.contentGroupId}, contenttype.cty_key as {itcg.contentTypeKey}, contenttype.cty_name as {itcg.contentTypeName}, contentimport.cti_importdate as {itcg.contentImportDate}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 7) AS {itcg.downloads7}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 30) AS {itcg.downloads30}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 90) AS {itcg.downloads90} FROM itemtocontentgroup JOIN item ON item.itm_sid = itemtocontentgroup.itm_sid JOIN contentimport ON item.cti_sid = contentimport.cti_sid JOIN contentgroup ON contentgroup.ctg_sid = itemtocontentgroup.ctg_sid JOIN contenttype ON contentgroup.cty_sid = contenttype.cty_sid WHERE itemtocontentgroup.ctg_sid=:contentGroupId ORDER BY downloads90]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:642)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:424)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
at net.netm.me.core.dao.hibernate.ItemToContentGroupDaoHibernate.findItemToContentGroupAndDownloadsAndReleaseDateByContentGroupId(ItemToContentGroupDaoHibernate.java:117)
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:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.aop.interceptor.AbstractTraceInterceptor.invoke(AbstractTraceInterceptor.java:113)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy53.findItemToContentGroupAndDownloadsAndReleaseDateByContentGroupId(Unknown Source)
at net.netm.me.core.dao.ItemToContentGroupDaoTest.testFindItemToContentGroupAndDownloadsAndReleaseDateByContentGroupId(ItemToContentGroupDaoTest.java:51)
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:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.hibernate.QueryException: No column name found for property [itemMasterOrderId] for alias [itcg] [SELECT DISTINCT itemtocontentgroup.icg_sid as {itcg.itemToContentGroupId}, itemtocontentgroup.icg_position as {itcg.position}, item.itm_sid as {itcg.itemId}, item.itm_orderid as {itcg.itemOrderId}, item.itm_masterorderid as {itcg.itemMasterOrderId}, item.itm_name2 as {itcg.artist}, item.itm_name1 as {itcg.title}, item.itm_updatedate, contentgroup.ctg_sid as {itcg.contentGroupId}, contenttype.cty_key as {itcg.contentTypeKey}, contenttype.cty_name as {itcg.contentTypeName}, contentimport.cti_importdate as {itcg.contentImportDate}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 7) AS {itcg.downloads7}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 30) AS {itcg.downloads30}, (SELECT SUM(imc_counter) FROM itemcounter WHERE itemcounter.itm_sid2 = item.itm_sid AND imc_date > current_date - 90) AS {itcg.downloads90} FROM itemtocontentgroup JOIN item ON item.itm_sid = itemtocontentgroup.itm_sid JOIN contentimport ON item.cti_sid = contentimport.cti_sid JOIN contentgroup ON contentgroup.ctg_sid = itemtocontentgroup.ctg_sid JOIN contenttype ON contentgroup.cty_sid = contenttype.cty_sid WHERE itemtocontentgroup.ctg_sid=:contentGroupId ORDER BY downloads90]
at org.hibernate.loader.custom.SQLQueryParser.resolveProperties(SQLQueryParser.java:262)
at org.hibernate.loader.custom.SQLQueryParser.substituteBrackets(SQLQueryParser.java:149)
at org.hibernate.loader.custom.SQLQueryParser.process(SQLQueryParser.java:85)
at org.hibernate.loader.custom.SQLCustomQuery.<init>(SQLCustomQuery.java:157)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:20)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:113)
at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:137)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:164)
at net.netm.me.core.dao.hibernate.ItemToContentGroupDaoHibernate$2.doInHibernate(ItemToContentGroupDaoHibernate.java:163)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
... 34 more
Here's the full ItemToContentGroupExtended.class:
Code:
public class ItemToContentGroupExtended {
private static final long serialVersionUID = -2465392632324750424L;
private Long itemToContentGroupId;
private String title;
private String artist;
private int position;
private Long itemId;
private Long itemOrderId;
private Long itemMasterOrderId;
private Long contentGroupId;
private String contentTypeKey;
private String contentTypeName;
private Date contentImportDate;
private int downloads7;
private int downloads30;
private int downloads90;
...getters/setters few logic ...
}
itemMasterOrderId property is there. Still I'm getting this exception. Cleaned my compiled classes and rebuild them again, still having the issue and the more I try, the more clueless I get. :(
If I remove item.masterorderid from the select I get the same exception for the download fields. So maybe I'm getting something wrong with the mappings?!
itemMasterOrderId is an int4 column in the db btw.