-->
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.  [ 3 posts ] 
Author Message
 Post subject: Issue using @NamedQuery
PostPosted: Tue Mar 25, 2008 9:27 am 
Newbie

Joined: Fri Mar 21, 2008 12:32 pm
Posts: 9
Hi All,

Anybody had issues using @NamedQuery? If yes, can you please take a look at the following and see whats wrong. Nothing seems to be wrong, but Hibernate 3.2 fails. The code fragment and Exception message are given below. HQL query and NamedNativeQuery was also tried as approaches, but both failed too.

@Entity
@Table(name="CONTACT")
@NamedQueries({ @NamedQuery(name = "selectall", query = "SELECT * FROM CONTACT") })
public class Contact {
---usual setter getters----
}


@NamedQuery annotation always throws the following exception at the following line: SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();

The stack trace of the exception is as follows:
<Fri Mar 21 15:14:22 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <table found: hibernatetutorial.contact>
<Fri Mar 21 15:14:22 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <columns: [lastname, firstname, email, id]>
<Fri Mar 21 15:14:22 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <foreign keys: []>
<Fri Mar 21 15:14:22 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <indexes: []>
<Fri Mar 21 15:14:22 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.SchemaUpdate> <BEA-000000> <schema update complete>
<Fri Mar 21 15:14:22 EDT 2008> <Trace> <org.hibernate.connection.DriverManagerConnectionProvider> <BEA-000000> <returning connection to pool, pool size: 1>
<Fri Mar 21 15:14:22 EDT 2008> <Debug> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Checking 1 named HQL queries>
<Fri Mar 21 15:14:22 EDT 2008> <Debug> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Checking named query: selectall>
<Fri Mar 21 15:14:22 EDT 2008> <Trace> <org.hibernate.engine.query.QueryPlanCache> <BEA-000000> <unable to locate HQL query plan in cache; generating (SELECT * FROM CONTACT)>
<Fri Mar 21 15:14:22 EDT 2008> <Debug> <org.hibernate.hql.ast.QueryTranslatorImpl> <BEA-000000> <parse() - HQL: SELECT * FROM CONTACT>
<Fri Mar 21 15:14:22 EDT 2008> <Error> <org.hibernate.hql.PARSER> <BEA-000000> <line 1:8: unexpected token: *>
<Fri Mar 21 15:14:22 EDT 2008> <Debug> <org.hibernate.hql.ast.ErrorCounter> <BEA-000000> <line 1:8: unexpected token: *>
org.hibernate.HibernateException: Errors in named queries: selectall
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:365)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
at hib.FirstExample.main(FirstExample.java:18)
<Fri Mar 21 15:14:22 EDT 2008> <Debug> <org.hibernate.hql.ast.AST> <BEA-000000> <--- HQL AST ---
\-[QUERY] 'query'
\-[SELECT_FROM] 'SELECT_FROM'
\-[FROM] 'FROM'
\-[RANGE] 'RANGE'
\-[IDENT] 'CONTACT'
>
<Fri Mar 21 15:14:22 EDT 2008> <Debug> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Checking 0 named SQL queries>
<Fri Mar 21 15:14:22 EDT 2008> <Error> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Error in named query: selectall>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 27, 2008 8:57 am 
Newbie

Joined: Thu May 17, 2007 9:49 am
Posts: 9
Try
Code:
@NamedQuery(name = "selectall", query = "SELECT c FROM Contact c")

or
Code:
@NamedNativeQuery(name="selectall", query="SELECT * FROM CONTACT", resultClass=Contact.class)

It should work...


Top
 Profile  
 
 Post subject: another solution to this @NamedQuery issue
PostPosted: Thu Mar 27, 2008 9:09 am 
Newbie

Joined: Fri Mar 21, 2008 12:32 pm
Posts: 9
Thanks maciejziaja, it works.

Another way this works is to use HQL as follows:

@NamedQuery(name = "selectall", query = "from hib.Contact")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.