Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table mapping problem

 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am newbie to Hibernate and I've been trying to implement it in a Java Web Project. I'm using Hibernate 3, GlassFish v3, Java EE 5, Java Platform JDK 1.6., and Oracle 11g. Everything seemed to be working fine but then this error appeared and I haven't found a solution:
org.hibernate.hql.ast.QuerySyntaxException: TableB is not mapped [from TableB] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister


I have used the name of the table as it appears in my mapping file, so I'm not sure why does this error happen. I've also tried to write the query as from package.Classname, and even though that error stopped showing up, I wasn't able to retrieve any results from my database. I have tried both queries in the HQL Query of Netbeans 6.8, and the results appeared normally.

Maybe it's something really simple but I just can't figure it out, hope someone could help me. Here are the files I've created:

TableB.hbm.xml



Helper.java



This is the full error trace:

[#|2010-02-17T02:28:25.040-0600|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=17;_ThreadName=httpSSLWorkerThread-8080-2;_RequestID=6d371219-a707-4d43-ac02-7a58b24a6d37;|
org.hibernate.hql.ast.QuerySyntaxException: TableB is not mapped [from TableB]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:313)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3353)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3237)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:724)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:575)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:292)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
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:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
at $Proxy57.createQuery(Unknown Source)
at util.Helper.report(Helper.java:69)
at org.apache.jsp.Report_jsp._jspService(Report_jsp.java from :169)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:411)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:290)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:271)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:202)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:206)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:150)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:632)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:577)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:571)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1080)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:272)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:637)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:568)
at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:813)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)
|#]


Sorry for the long post.

Thanks in advance :) !!
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try including this property in hibernate.cfg.xml file

<property name="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</property>
 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saipraneeth, thanks for your reply! I've just tried adding that property to my hibernate config, but my problem continues. Any other suggestion?
 
Justin Chi
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pose your hibernate.cfg.xml, I doubt you have <mapping resource="util/TableB.hbm.xml" /> inside.
 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Justin, here is my hibernate.cfg:


As you may see the mapping is there, which is why I can't understand this kind of error, what could be missing?
If you have any other suggestion please let me know. Anyway, thanks for your reply!
 
Justin Chi
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you change hbm.xml using <hibernate-mapping package="util"> <class name="TableB" table="TABLEB"> .... and run again, by right it should be the same as current one but I just want to see the exception.
BTW , your other tables also failed?
 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Justin! Thanks for your quick answer, unfortunately as you said, the error continues after I changed that line in the mapping. Here is the exception:

[#|2010-02-17T23:10:24.804-0600|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=41;_ThreadName=httpSSLWorkerThread-8080-4;_RequestID=282b8c6c-98ff-41be-924f-7c10f9f19d9c;|
org.hibernate.hql.ast.QuerySyntaxException: TableB is not mapped [from TableB ]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:313)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3353)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3237)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:724)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:575)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:292)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)
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:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:344)
at $Proxy58.createQuery(Unknown Source) ...

As you may see, it hasn't changed, and yes, the same thing happens with my other tables

Any other suggestion will be really appreciated !
 
Justin Chi
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By now the only thing I can suggest is try HibernateUtil.getSessionFactory().getClassMetadata(TableB.class), meta data should have enough info for you to find the mapped object name. Good luck!
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the thing is hibernate 3 uses an ANTLR based parser in org.hibernate.hql.ast
if your antlr.jar file is also a included in the build path of your project but it will be override by the server based antlr.jar file, in order to overcome this you have append this file in the classpath of the server.
 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Justin, thanks for your suggestion, it was a good idea, but when I tried to implement it I get a null value, I don't know why. Obviously it's not finding the mapping but, why?

Hi, Saipraneeth, also thanks for your comment, but I didn't understand it quite well , sorry . Do you think that the antlr.jar maybe causing this problem? Where do you say I can find it?


 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hibernate has two hql parser implementations, one is
org.hibernate.hql.ast.ASTQueryTranslatorFactory
the other is org.hibernate.hql.classic.ClassicQueryTranslatorFactory
these are the only two possible values which can specify in the hibernate.cfg.xml for the property hibernate.query.factory_class

now the thing is org.hibernate.hql.ast is ANTLR-based parser where as org.hibernate.loader.hql defines the loader for the AST-based query parser.

dont confuse with the name that org.hibernate.hql.ast is a AST-based parser where it is not.

as it is antlr based you must include the antlr.jar file into your build path, which when archived(i;e .war file) and uploaded to the server(any of the one tomcat, weblogic, JBoss, glass fish, etc), as i worked with weblogic the antlr.jar file must be given to the weblogic before uploading it into it(i;e specify it in it's PRE-CLASSPATH).

so i guess this must be also the same to even the others, so specify the antlr.jar file in the classpath of the your respective server.
Do you think that the antlr.jar maybe causing this problem? Where do you say I can find it?

i don't understand whether you are asking that in your local disk or from web?


 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saipraneeth! Thanks very much for your help, fortunately I discovered that the problem was caused by an old hibernated config file that didn't reflect the mapping of my tables . Next time I will be more careful in order to avoid this type of errors.

Anyway, thanks for your posts!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic