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
|