Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with HQL query -- to return few columns of a Table

 
Ravi Goli
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Iam using HQL (Hibernate) to query a Table for selecting few fields of a record of the Table in the DataBase.

My Query is like the Following, Here Iam selecting 2 of the 20 Cloumns of my Persisting Object - ModelDTO....

So, I've Created a New DTO with these two fields and Have written my Query as the following:

String query = " select new BasicModelDTO(model.modelName, model.serialNumber) from " + modelDTO.getClass().getName() +
" as model where model.planNum = '" + modelDTO.getPlanNum()+"'";

StringBuffer searchQuery = new StringBuffer(query);

Session hSession = this.openSession();
results = this.retrieve(searchQuery);


When, I Run my client....Iam getting the Following Error.....



2005-11-21 12:22:02,363 ERROR [org.hibernate.hql.PARSER] *** ERROR: Unable to locate class [BasicModelDTO]
[cause=java.lang.ClassNotFoundException: No ClassLoaders found for: BasicModelDTO]
2005-11-21 12:22:02,373 INFO [STDOUT] org.hibernate.hql.ast.QuerySyntaxError: Unable to locate class [BasicModelDTO] [ select new BasicModelDTO(model.modelName, model.serialNumber) from com.tollbrothers.archonline.dto.reference.ModelDTO as model where model.planNum = '215']
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:196)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.tollbrothers.sharedservices.persistence.DAOImpl.retrieve(Unknown Source)
at com.tollbrothers.archonline.persistence.database.archdoc.MasterPlanDAO.getBasicDetailsForModel(Unknown Source)
at com.tollbrothers.archonline.services.archdoc.masterplanupdates.MasterPlanOrderBO.retrieve(Unknown Source)
at com.tollbrothers.archonline.services.archdoc.masterplanupdates.MasterPlanOrderBean.retrieve(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:324)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:113)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:51)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:105)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:313)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:146)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:122)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:870)
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:324)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:144)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
Caused by: Unable to locate class [BasicModelDTO]
[cause=java.lang.ClassNotFoundException: No ClassLoaders found for: BasicModelDTO]
at org.hibernate.hql.ast.ConstructorNode.resolveConstructor(ConstructorNode.java:115)
at org.hibernate.hql.ast.ConstructorNode.prepare(ConstructorNode.java:86)
at org.hibernate.hql.ast.HqlSqlWalker.processConstructor(HqlSqlWalker.java:543)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1598)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1467)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1041)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:380)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
... 50 more
2005-11-21 12:22:02,433 INFO [STDOUT] Model Results returned in DAO are NULL
2005-11-21 12:22:02,433 INFO [STDOUT] Model Results returned in DAO are NULL



Can, Somebody, help me resolve this error....

Ravi.
 
Peter Laurinec
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.
You do not create new instance of a class in a query.
If you are trying to query 2 columns from some class the query should look like this:
 
Scott Johnson
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your classname in the select clause should be a fully qualified class name.
 
A Developer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, thank you, Scott! I am new to Hibernate and was having the same problem. I could not find the answer anywhere. Now I can do my cool query!

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"A Developer"

Welcome to JavaRanch!

Perhaps you didn't notice when you registered but, though we have few rules here, one is that all screen names conform to our naming policy. Please go here and update it. Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic