-->
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.  [ 4 posts ] 
Author Message
 Post subject: Annotation and Java persistence
PostPosted: Thu Sep 21, 2006 2:40 pm 
Newbie

Joined: Thu Feb 24, 2005 10:09 am
Posts: 11
Using Hello World example created simple NewMessage class that is annotated. I did this to leave in mapped Message class in HelloWorld application. I am also using newest jars 3.2.0CR2 for annotations,entitymanager, tools is 3.2.0beta 7. Core is newest release. When query line :

List messages = newEm
.createQuery("from NewMessage m order by m.text asc")
.getResultList();


is ran the following exception is returned.

14:30:07,845 DEBUG QueryPlanCache:70 - unable to locate HQL query plan in cache; generating (from NewMessage m order by m.text asc)
14:30:08,436 DEBUG QueryTranslatorImpl:246 - parse() - HQL: from hello.NewMessage m order by m.text asc
14:30:08,486 DEBUG AST:266 - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'from'
| \-[RANGE] 'RANGE'
| +-[DOT] '.'
| | +-[IDENT] 'hello'
| | \-[IDENT] 'NewMessage'
| \-[ALIAS] 'm'
\-[ORDER] 'order'
+-[DOT] '.'
| +-[IDENT] 'm'
| \-[IDENT] 'text'
\-[ASCENDING] 'asc'

14:30:08,486 DEBUG ErrorCounter:68 - throwQueryException() : no errors
14:30:08,756 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
14:30:08,846 DEBUG FromElement:105 - FromClause{level=1} : hello.NewMessage (m) -> newmessage0_
14:30:08,846 DEBUG FromReferenceNode:51 - Resolved : m -> newmessage0_.MESSAGE_ID
14:30:08,856 DEBUG DotNode:541 - getDataType() : text -> org.hibernate.type.StringType@eb7331
14:30:08,856 DEBUG FromReferenceNode:51 - Resolved : m.text -> newmessage0_.MESSAGE_TEXT
14:30:08,856 DEBUG HqlSqlBaseWalker:117 - select : finishing up [level=1, statement=select]
14:30:08,866 DEBUG HqlSqlWalker:516 - processQuery() : ( SELECT ( FromClause{level=1} NEW_MESSAGE newmessage0_ ) ( order ( newmessage0_.MESSAGE_TEXT newmessage0_.MESSAGE_ID text ) asc ) )
Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: JPA-QL compliance requires select clause [from hello.NewMessage m order by m.text asc]
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:628)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95)
at hello.HelloWorld.main(HelloWorld.java:74)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: org.hibernate.hql.ast.QuerySyntaxException: JPA-QL compliance requires select clause [from hello.NewMessage m order by m.text asc]
at org.hibernate.hql.ast.tree.SelectClause.initializeDerivedSelectClause(SelectClause.java:261)
at org.hibernate.hql.ast.HqlSqlWalker.createSelectClauseFromFromClause(HqlSqlWalker.java:721)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:531)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:92)



I am a little stumped. Any quick thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 2:49 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The exception message should be self-explanatory. Don't copy paste stuff from the MEAP chapters, they are an early draft with many many bugs. Use the source that is now on http://caveatemptor.hibernate.org/


Top
 Profile  
 
 Post subject: Thanks for quick reply
PostPosted: Thu Sep 21, 2006 3:20 pm 
Newbie

Joined: Thu Feb 24, 2005 10:09 am
Posts: 11
Will use caveat emptor. But was not copying and pasting. As I explained was trying NewMessage class (annotated) with Message class and read both entity manger release notes (lib requirements) and entity manager reference download docs before posting. Sorry the HQL seemed to have package name HELLO prepended to from when debugging was changed yet exception was thrown and that was what I didn't understand.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 3:35 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You did copy this code from the unedited draft. There is no other place where "from Message m" is in the query. The Getting Started source you can download has "select m from Message m".


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