-->
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: Hibernate 3.1 problem
PostPosted: Wed Jun 21, 2006 2:44 am 
Newbie

Joined: Wed Jun 21, 2006 2:07 am
Posts: 1
Hi,
I am using a named query to retrived partial POJO object. If I use
return alias and give POJO Object I am getting following exception.
The Hibernate version used here is 3.1.
Does anyboby know the cause of this error.

<sql-query name="getAdoptedChildCategories">
<return alias="category" class="nz.co.telecom.directories.selfservice.business.category.YpCategory">
<return-property name="id" column="CATEGORY_ID"/>
<return-property name="categoryName" column="CATEGORY_NAME"/>
<![CDATA[Select CATEGORY_ID as categoryId, CATEGORY_NAME as categoryName
from YP_CATEGORY, YP_CATEGORY_JN where
YP_CATEGORY_JN.JOIN_TYPE = 1 AND
YP_CATEGORY.CATEGORY_ID = YP_CATEGORY_JN.CHILD_ID AND
YP_CATEGORY_JN.PARENT_ID=? order by categoryName]]>
</sql-query>
Throws following exception as we can not return the alias category if we are not retrieving all the objects for that category(Excluding the set which are loaded lazily). So instead of putting only two columns if we retrieve all columns then this will degrade the performance since we are carrying whole data even if the UI don't need the same.
JDBC exception on Hibernate data access: could not execute query; nested exception is java.sql.SQLException: Invalid column name
java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3295)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1914)
at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1563)
at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
at org.hibernate.type.IntegerType.get(IntegerType.java:28)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:113)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:102)
at org.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:1088)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:554)
at org.hibernate.loader.Loader.doQuery(Loader.java:689)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:117)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1672)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:147)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:169)
at nz.co.telecom.directories.selfservice.integration.BaseHibernateDAO.getNamedQuery(BaseHibernateDAO.java:335)
at nz.co.telecom.directories.selfservice.integration.BaseHibernateDAO$$FastClassByCGLIB$$603f30a.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
at nz.co.telecom.directories.utility.AroundCacheAdvice.invoke(AroundCacheAdvice.java:105)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:643)
at nz.co.telecom.directories.selfservice.integration.category.YpCategoryDAOImpl$$EnhancerByCGLIB$$5679745.getNamedQuery(<generated>)
at nz.co.telecom.directories.selfservice.business.category.CategoryStructureServiceImpl.getAllTrueChildCategories(CategoryStructureServiceImpl.java:710)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
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 $Proxy1.getAllTrueChildCategories(Unknown Source)
at nz.co.telecom.directories.selfservice.business.category.CategoryStructureServiceTest.testGetAllChildCategories(CategoryStructureServiceTest.java:815)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at nz.co.telecom.directories.selfservice.TestAll.main(TestAll.java:52)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 1:20 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Hibernate, being an ORM and not a partial-ORM, does not support partial objects. This is quite handy, seeing as java is an object oriented language, and converting it to a partial-object language would be well outside hibernate's scope.

You have alternatives: either change your query to return scalars (return-scalar, ref docs section 16.3), or change it to HQL and use HQL's "select new YourObject( ... )" syntax (ref docs section 14.5).

...

So yellow pages is backed by hibernate, huh? Cool. Now if only it allowed more than 200 results...

_________________
Code tags are your friend. Know them and use them.


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.