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: Quote:
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
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 15/02/2010 02:29:56 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="util.TableB" schema="SYSTEM" table="TABLEB">
<id name="id" type="string">
<column length="4" name="ID"/>
<generator class="assigned"/>
</id>
<property name="name" type="string">
<column length="55" name="NAME"/>
</property>
</class>
</hibernate-mapping>
Helper.java
Code:
package util;
import java.util.*;
import org.hibernate.Query;
import org.hibernate.Session;
public class Helper {
Session session = null;
public Helper() {
try{
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
}
catch(Exception e) {
e.printStackTrace();}
}
public List report(String b) {
List<TableB> resB = null;
try {
this.session.beginTransaction();
Query q = session.createQuery("from TableB");
for(Iterator it=q.iterate(); it.hasNext();){
TableB b =(TableB)it.next();
resB.add(b);
}
}
catch (Exception e) {
e.printStackTrace();
}
return resB;
}
}
This is the error trace:
Quote:
[#|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)
...
Sorry for the long post.
Any suggestion will be great. Thanks in advance!! :)