-->
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: Very Strange Issue with @NamedQuery in Hibernate 3.2
PostPosted: Fri Mar 21, 2008 2:35 pm 
Newbie

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

I am having a strange issue with the @NamedQuery annotation. Any help is much appreciated.

Here is the problem I am having: I created a small database in mySql and use Hibernate 3 with annotations to insert and retrieve information from the database.

Everything works very well, until @NamedQueries came into picture.

I use a simple "select * from contact" query in the annotation, but it fails saying "unexpected token".

I use this annotation in the mapping class (the one which represents a row in the database), as shown below.
@Entity
@Table(name="CONTACT")
@NamedQueries({
@NamedQuery(name = "selectall", query = "SELECT * FROM CONTACT")
})
public class Contact {
private String firstName;
private String lastName;
private String email;
private int id;
.... here goes the regular getters/setters etc
}

But I receive an exception at the following line in the class where I initialize Hibernate as shown below:
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();

The exact exception I am getting is as shown below:
<Fri Mar 21 14:29:57 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <table found: hibernatetutorial.contact>
<Fri Mar 21 14:29:57 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <columns: [lastname, firstname, email, id]>
<Fri Mar 21 14:29:57 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <foreign keys: []>
<Fri Mar 21 14:29:57 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.TableMetadata> <BEA-000000> <indexes: []>
<Fri Mar 21 14:29:57 EDT 2008> <Info> <org.hibernate.tool.hbm2ddl.SchemaUpdate> <BEA-000000> <schema update complete>
<Fri Mar 21 14:29:57 EDT 2008> <Trace> <org.hibernate.connection.DriverManagerConnectionProvider> <BEA-000000> <returning connection to pool, pool size: 1>
<Fri Mar 21 14:29:57 EDT 2008> <Debug> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Checking 1 named HQL queries>
<Fri Mar 21 14:29:57 EDT 2008> <Debug> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Checking named query: selectall>
<Fri Mar 21 14:29:57 EDT 2008> <Trace> <org.hibernate.engine.query.QueryPlanCache> <BEA-000000> <unable to locate HQL query plan in cache; generating (SELECT * FROM CONTACT contact)>
<Fri Mar 21 14:29:57 EDT 2008> <Debug> <org.hibernate.hql.ast.QueryTranslatorImpl> <BEA-000000> <parse() - HQL: SELECT * FROM CONTACT contact>
<Fri Mar 21 14:29:57 EDT 2008> <Error> <org.hibernate.hql.PARSER> <BEA-000000> <line 1:8: unexpected token: *>
<Fri Mar 21 14:29:57 EDT 2008> <Debug> <org.hibernate.hql.ast.ErrorCounter> <BEA-000000> <line 1:8: unexpected token: *>
<Fri Mar 21 14:29:57 EDT 2008> <Debug> <org.hibernate.hql.ast.AST> <BEA-000000> <--- HQL AST ---
\-[QUERY] 'query'
\-[SELECT_FROM] 'SELECT_FROM'
\-[FROM] 'FROM'
\-[RANGE] 'RANGE'
+-[IDENT] 'CONTACT'
\-[ALIAS] 'contact'
>
<Fri Mar 21 14:29:57 EDT 2008> <Debug> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Checking 0 named SQL queries>
<Fri Mar 21 14:29:57 EDT 2008> <Error> <org.hibernate.impl.SessionFactoryImpl> <BEA-000000> <Error in named query: selectall>
Inside Exception block
Errors in named queries: selectall
Inside finally block
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)

Thanks,
VPC


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 8:41 am 
Newbie

Joined: Tue Jul 08, 2008 10:21 am
Posts: 1
instead of select * u have to type
FROM CONTACT

u dont need to give select *


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.