-->
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: Criteria projection query with nested property
PostPosted: Mon Jun 04, 2007 12:14 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 12:09 am
Posts: 30
Hibernate version: 3.2

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

Session session = this.getCurrentSession();
Criteria crit = session.createCriteria(UniUnit.class);
crit.createAlias("uni", "uni");

/*
* prefix is needed to ensure the alias name is different from the property name
* this is a workaround to problem where Hibernate uses alias names in where clause
* http://opensource.atlassian.com/project ... se/HHH-817
*/
final String prefix = PrefixedAliasToBeanResultTransformer.ALIAS_PREFIX;

crit.setProjection(Projections.distinct(Projections.projectionList()
.add(Projections.property("id.uniCode"), prefix + "id.uniCode")
.add(Projections.property("id.unitCode"), prefix + "id.unitCode")
.add(Projections.property("description"), prefix + "description")
.add(Projections.property("weighting"), prefix + "weighting")
.add(Projections.property("uni.description"), prefix + "uni.description")
)).setResultTransformer(new PrefixedAliasToBeanResultTransformer(UnitSearchResult2.class));

...

if (criteria.getMaxRowsReturned() > 0) {
crit.setMaxResults(criteria.getMaxRowsReturned());
}

Collection items = crit.list();

sLogger.trace("unitCategorySearch() - End");
return items;

Full stack trace of any exception that occurs:

org.hibernate.PropertyNotFoundException: Could not find setter for id.uniCode on class au.edu.nsw.det.csa.eat.uni.datatypes.UnitSearchResult2
at org.hibernate.property.ChainedPropertyAccessor.getSetter(ChainedPropertyAccessor.java:44)
at au.edu.nsw.det.csa.eat.hibernate.transform.PrefixedAliasToBeanResultTransformer.transformTuple(PrefixedAliasToBeanResultTransformer.java:63)
at org.hibernate.loader.criteria.CriteriaLoader.getResultColumnOrRow(CriteriaLoader.java:115)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:606)
at org.hibernate.loader.Loader.doQuery(Loader.java:701)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at au.edu.nsw.det.csa.eat.uni.dao.priv.hibernate.UniDataDAOImpl.unitCategorySearch(UniDataDAOImpl.java:397)
at au.edu.nsw.det.csa.eat.uni.ejb.priv.UniDataManagerBean.unitCategorySearch(UniDataManagerBean.java:398)
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 com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.TxRequiredInterceptor.invoke(TxRequiredInterceptor.java:50)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
at com.evermind.server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:55)
at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:87)
at UniDataManagerEJB_LocalProxy_1b4ep8c.unitCategorySearch(Unknown Source)
at au.edu.nsw.det.csa.eat.uni.delegate.UniDataManagerDelegate.unitCategorySearch(UniDataManagerDelegate.java:194)
at au.edu.nsw.det.csa.eat.uni.actions.UniSearchAction.searchUnit(UniSearchAction.java:124)
at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.apache.struts.actions.MappingDispatchAction.execute(MappingDispatchAction.java:169)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
at au.edu.nsw.det.set.themes.servlet.StyleSheetFilter.doFilter(StyleSheetFilter.java:134)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at au.edu.nsw.det.set.security.menus.filters.MenuFilter.doFilter(MenuFilter.java:148)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at au.edu.nsw.det.set.security.authorisation.filters.AuthorisationFilter.doFilter(AuthorisationFilter.java:176)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at au.edu.nsw.det.set.security.authentication.filters.AuthenticationFilter.doFilter(AuthenticationFilter.java:198)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:17)
at au.edu.nsw.det.csa.eat.common.filters.RequestHistoryFilter.doFilter(RequestHistoryFilter.java:44)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:620)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:369)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:865)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:447)
at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:215)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:239)
at oracle.oc4j.network.ServerSocketAcceptHandler.access$700(ServerSocketAcceptHandler.java:34)
at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:880)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:595)
4/

Name and version of the database you are using: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production

The generated SQL (show_sql=true):

select * from ( select distinct this_.UNI_CODE as y0_, this_.UNIT_CODE as y1_, this_.DESCRIPTION as y2_, this_.WEIGHTING as y3_, uni1_.DESCRIPTION as y4_ from eatdba.UNI_UNIT this_ inner join eatdba.UNI uni1_ on this_.UNI_CODE=uni1_.UNI_CODE inner join eatdba.ASSESSMENT_CATEGORY_UNIT aunit2_ on this_.UNI_CODE=aunit2_.UNI_CODE and this_.UNIT_CODE=aunit2_.UNIT_CODE ) where rownum <= ?



I have used a custom transformer to resolve the problem HHH-817 where Hibernates generates invalid SQL (ie alias in where clause). I use a projection query in order to control the no. of rows returned.

What I would like to do is have the alias transformer correctly populate nested properties (eg id.uniCode) - My question is: Is there a Hibernate property accessor class which already manages this or do I need to write my own logic in the transformer class, and does this involve using something other than ChainedPropertyAccessor?

Thanks,
Paul


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.