• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

EVENTS is not mapped [FROM EVENTS]

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am new to hibernate, i am following with hibernate tutorial.
DB : HSQLBD


storing records succussfully but Could not able to retrive the records.
Facing problem with table mapping.

ERROR :


run:
[java] Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxExceptio
n: EVENTS is not mapped [FROM EVENTS]
[java] at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassP
ersister(SessionFactoryHelper.java:158)
[java] at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(
FromElementFactory.java:87)
[java] at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClau
se.java:70)
[java] at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWa
lker.java:255)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBa
seWalker.java:3056)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlS
qlBaseWalker.java:2945)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBas
eWalker.java:688)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalk
er.java:544)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlS
qlBaseWalker.java:281)
[java] at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBase
Walker.java:229)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTransl
atorImpl.java:228)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTran
slatorImpl.java:160)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTransl
atorImpl.java:111)
[java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.j
ava:77)
[java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.j
ava:56)
[java] at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(Que
ryPlanCache.java:72)
[java] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(Abstra
ctSessionImpl.java:133)
[java] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSe
ssionImpl.java:112)
[java] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1
623)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcces
sorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMet
hodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.hibernate.context.ThreadLocalSessionContext$TransactionPr
otectionWrapper.invoke(ThreadLocalSessionContext.java:301)
[java] at $Proxy0.createQuery(Unknown Source)
[java] at events.EventManager.listEvents(Unknown Source)
[java] at events.EventManager.main(Unknown Source)
[java] Java Result: 1

code:

Event.hbm.xml
-------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="events.Event" table="EVENTS" >
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>

</hibernate-mapping>


EventManager.java
----------------
package events;
import org.hibernate.Query;
import org.hibernate.Session;


import java.util.Date;
import java.util.List;


import util.HibernateUtil;

public class EventManager {

public static void main(String[] args) {
EventManager mgr = new EventManager();

if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date());
}else if (args[0].equals("list")) {
List events = mgr.listEvents();
for (int i = 0; i < events.size(); i++) {
Event theEvent = (Event) events.get(i);
System.out.println("Event: " + theEvent.getTitle() +
" Time: " + theEvent.getDate());
}
}

HibernateUtil.getSessionFactory().close();
}

private void createAndStoreEvent(String title, Date theDate) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

Event theEvent = new Event();

theEvent.setTitle(title);
theEvent.setDate(theDate);

session.save(theEvent);

session.getTransaction().commit();


}
private List listEvents() {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

List result = session.createQuery("FROM EVENTS").list();

session.getTransaction().commit();
return result;
}

}

please any body can help me?

Thanks in advance.

regards,
Amar
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember in HQL you are querying classes not tables. Your class is called Event, not Events.
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a HQL query, it is the name of the class (Event), and not the name of the database table (EVENTS), that you need to specify in the FROM clause.
 
amar rajula
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is working now.
Thank you very much for you both.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic