-->
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: createSqlQuery with t.a1, t.a2, ... works, but {t.*} doesn't
PostPosted: Wed Jun 27, 2007 11:46 am 
Newbie

Joined: Sun Jun 24, 2007 11:43 am
Posts: 1
The essence of my problem is this: Using createSqlQuery to query for a complete list of table attributes (i.e table.attribute1, table.attribute2, ...) works, but replacing the list with {table.*} causes an exception.

In the java classes used for the below queries, Subscription inherits Product. Also, notice that the generated alias s_1_ in the Hibernate query is never actually mapped by Hibernate. I'll be very appreciative of any help to resolve this issue:

Hibernate version:
3.2
Mapping documents:

Code between sessionFactory.openSession() and session.close():
Using Spring 2.0.4 and extending HibernateDaoImpl:
List subscriptions = getSession().createSQLQuery("select "
+ " {s.*} "
+ " from"
+ " subscription s "
+ " inner join"
+ " product p "
+ " on s.ID = p.ID")
.addEntity("s", Subscription.class)
.list();

Full stack trace of any exception that occurs:
2007-06-27 16:58:14,309 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1054, SQLState: 42S22
2007-06-27 16:58:14,309 ERROR [org.hibernate.util.JDBCExceptionReporter] - Unknown column 's_1_.Description' in 'field list'
2007-06-27 16:58:14,314 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/backend].[backend]] - Servlet.service() for servlet backend threw exception
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 's_1_.Description' in 'field list'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1403)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
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:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
at com.moobi.backend.dao.ProductInfoDaoImpl.getSubscriptions(ProductInfoDaoImpl.java:211)
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:304)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:139)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:203)
at $Proxy37.getSubscriptions(Unknown Source)
at com.moobi.backend.services.SubscriptionServiceImpl.getSubscriptions(SubscriptionServiceImpl.java:76)
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:304)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:197)
at $Proxy40.getSubscriptions(Unknown Source)
at com.moobi.backend.web.SubscriptionController.handleRequest(SubscriptionController.java:26)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:839)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:774)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:460)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)


Name and version of the database you are using:
mysql 5.0.22
The generated SQL (show_sql=true):
Hibernate: select s.ID as ID9_0_, s_1_.Description as Descript2_9_0_, s_1_.DoSendAboInfo as DoSendAb3_9_0_, s_1_.IsDeleted as IsDeleted9_0_, s_1_.ItemID as ItemID9_0_, s_1_.OurItemNr as OurItemNr9_0_, s_1_.Price as Price9_0_, s_1_.Title as Title9_0_, s_1_.ProductTypeID as ProductT9_9_0_, s_1_.VendorID as VendorID9_0_, s.IsDefaultSub as IsDefaul2_67_0_, s.IsVisible as IsVisible67_0_, s.PeriodicPrice as Periodic4_67_0_, s.PortingText as PortingT5_67_0_, s.SortWeight as SortWeight67_0_, s.SubscriptionURL as Subscrip7_67_0_, s.ContractPeriodID as Contract8_67_0_, s.ID as ID67_0_ from subscription s inner join product p on s.ID = p.ID

However, the following query works:
List subscriptions = getSession().createSQLQuery("select"
+ " p.ID,"
+ " p.ProductTypeID,"
+ " p.VendorID,"
+ " p.Price,"
+ " p.ItemID,"
+ " p.IsDeleted,"
+ " p.DoSendAboInfo,"
+ " p.OurItemNr,"
+ " p.Title,"
+ " p.Description,"
+ " s.PeriodicPrice,"
+ " s.IsVisible,"
+ " s.SortWeight,"
+ " s.IsDefaultSub,"
+ " s.ContractPeriodID,"
+ " s.SubscriptionURL,"
+ " s.PortingText"
+ " from"
+ " subscription s"
+ " inner join"
+ " product p "
+ " on s.ID = p.ID")
.addEntity("s", Subscription.class)
.list();

The following HQL also works:
getHibernateTemplate().find("from Subscription");


Top
 Profile  
 
 Post subject: Solution to your problem
PostPosted: Sun Jan 18, 2009 4:01 pm 
Newbie

Joined: Sat Jan 17, 2009 3:31 am
Posts: 2
SQLQuery query = getSession().createSQLQuery("SELECT {c.*}, {p.*} FROM Child c, Parent p WHERE c.parentId = p.id")
.addEntity("c", Child.class).addEntity("p", Parent.class);

Notice that the aliases 'c' and 'p' for Child and Parent table, respectively, are consistent for all places. That's the key.

_________________
Maximos


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.