This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi, I am new to hibernate and have come across some hurdles which I could solve. I am stuck with one error saying Table is not mapped. I am using Oracle DB.
Aftr executing the above script; I recieve the message:
D:\projects\springHibn>ant run Buildfile: build.xml
prepare: [copy] Copying 1 file to D:\projects\springHibn\war\WEB-INF [copy] Copying 1 file to D:\projects\springHibn\war\properties
compile:
run: [java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). [java] log4j:WARN Please initialize the log4j system properly. [java] org.hibernate.hql.ast.QuerySyntaxException: TEST.EVENT is not mapped [from EVENT] [java] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:158) [java] at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87) [java] at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70) [java] at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255) [java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056) [java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945) [java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688) [java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544) [java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281) [java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229) [java] at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228) [java] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160) [java] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111) [java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77) [java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56) [java] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72) [java] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133) [java] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112) [java] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623) [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [java] at java.lang.reflect.Method.invoke(Method.java:324) [java] at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301) [java] at $Proxy0.createQuery(Unknown Source) [java] at events.EventManager.store(EventManager.java:44) [java] at events.EventManager.main(EventManager.java:17)
It would be nice if anyone provides me the solution.
First, we will repost your code surrounded by the CODE tags, which get generated when you click the "CODE" button underneath the "Add Reply" button when posting on JavaRanch, so that we have your code indentation there and makes it easier to read.
So now that I see your code easier to read, it is simple, your HQL is incorrect.
You have "from EVENT", so Hibernate is looking for a class called, with the same all-upper case, "EVENT", but your mapped class is "Event", so change your HQL from "from EVENT" to "from Event"
And it is preferred to call list() on the Query object to get the results. Also use Query interface instead of (QueryImpl), it is always better to code to an interface than a concrete class.
Mark
Vamsi Mohan Pemmaraju
Greenhorn
Joined: Jul 15, 2007
Posts: 14
posted
0
Thanks Mark,
Your suggestion was very useful. I have solved the my problem.
THE DEFINITIONS FOR THE *.HBM.XML ARE AS BELOW: 1) COMPONENT.HBM.XML <hibernate-mapping> <class name="events.Component" table="COMPONENT"> <composite-id name="cmpnt_id" class="events.Component"> <key-property name="cmpnt_id"/> <key-property name="cmpnt_tech_id"/> </composite-id> <property name="cmpnt_nm"/>
My code was: public String retrieve(Long cmpnt_id) { Component e = (Component)session.load(Component.class.getName(), cmpnt_id); return e.getCmpnt_nm(); }
I was not succesful in executing with the above configurations. the error was: org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class events.Component, got class java.lang.Long
Another thing is, do we need to have individual .hbm.xml for each class or can we club two class definitions in one. If yes, are there any restrictions or conditions.
Vamsi, can you actually post your last question as a new thread. It is a different problem, and therefore you might get better responses as a new thread rather than adding to this one.