-->
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.  [ 7 posts ] 
Author Message
 Post subject: addAnnotatedClass() not working,
PostPosted: Thu Jul 31, 2008 2:58 pm 
Newbie

Joined: Tue Dec 18, 2007 7:41 am
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.5
Mapping documents:
None
Code between sessionFactory.openSession() and session.close():
None
Full stack trace of any exception that occurs:
org.hibernate.hql.ast.QuerySyntaxException: Hotel is not mapped [from Hotel]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
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)
Name and version of the database you are using:
INFO [org.hibernate.cfg.SettingsFactory]: JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.2.2.1 - (538595)
The generated SQL (show_sql=true):
None
Debug level Hibernate log excerpt:
Not much useful..

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Hi,
I am trying to build a HQL Editor. I use a custom classloader to load hibernate jars and user project classes. the following code adds the annotated class to the config.

Class configClass = customClassLoader.loadClass("org.hibernate.cfg.AnnotationConfiguration");
customConfiguration = (AnnotationConfiguration) configClass.newInstance();
clazz = reflectHelper.classForName(annotatedPOJO.getName());
customConfiguration.addAnnotatedClass(clazz);

I am trying to get the equivalent SQL using the following code :

SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) hibernateConfiguration.buildSessionFactory();
HQLQueryPlan queryPlan = sessionFactoryImpl.getQueryPlanCache().getHQLQueryPlan(hqlEditor.getText(), true, Collections.EMPTY_MAP);

I get the exception (above) at this last line.. Could any one help me in finding whats going wrong here ? This case is only annotated POJO class. The case with annotated class with mapping XML works fine.

Thanks,
-Vadiraj.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 01, 2008 9:48 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
So, there are two things you need to confirm.

First, Hotel is decorated with an @Entity tag, correct?

Secondly, it is added to the Hibernate AnnotationConfiguration object at some point, right? If not, Hibernate won't know how to map it.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 01, 2008 1:16 pm 
Newbie

Joined: Tue Dec 18, 2007 7:41 am
Posts: 7
Hi Cameron,

Yes and Yes to your both questions...
Hotel has @Entity annotation and as you can see from the code snippet that I posted earlier, its added using addAnnotatedClass() of AnnotationConfiguration.
I would like to add here that, if I have the corresponding mapping file for Hotel, and add it to the same AnnotationConfiguration object, everything works like a charm..

Thanks.
-Vadiraj.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 02, 2008 4:48 pm 
Newbie

Joined: Tue Dec 18, 2007 7:41 am
Posts: 7
Can somebody answer pl ? This is urgent.
-V


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 04, 2008 2:39 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi Vadiraj,

Could you try using the same classloader? Isn't it possible your customClassloader and you SessionFactory are returning the types so that Hotel.class!=Hotel.class ?

BTW, do you know about the Hibernate Tools? it includes a very nice HQL editor (among other good stuff). It's also open, so you could look at that code if you need to build your own.

regards,

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 7:39 am 
Newbie

Joined: Tue Dec 18, 2007 7:41 am
Posts: 7
Hi Sanne,

As you pointed out, it was a problem with Configuration and SessionFactory objects being loaded by different instances of the same classloaders !

Thanks for the help. I know about JBoss Hibernate tools plugin for JBoss IDE and Eclipse. I am currently building HQL Editor for NetBeans IDE.

-Vadiraj.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 7:54 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
nice you solved, and
looking forward to see your HQL editor in action!

Sanne

_________________
Sanne
http://in.relation.to/


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