-->
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.  [ 6 posts ] 
Author Message
 Post subject: QuerySyntaxException: EMPLOYEE is not mapped
PostPosted: Thu Oct 01, 2009 1:47 pm 
Newbie

Joined: Thu Oct 01, 2009 12:58 pm
Posts: 3
I modified code from chapter 2 of the Java Persistence book. I have been able to get this same code to insert new records but I cannot get it to read from the table. I am doing this within a servlet. I originally recieved a message that it could not find the mapping file, but I fixed that by copying the file to the classes directory.

Anyone see what I am missing?

Here is the DDL:
Code:
create table EMPLOYEE
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
employee varchar(100),
lastChanged TIMESTAMP
);


Here is the mapping file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

    <class
        name="com.paramountProfressional.Employee"
        table="EMPLOYEE">

        <id
            name="id"
            column="id">
            <generator class="native"/>
        </id>

        <property
            name="employee"
            column="employee"/>
           
        <property
            name="lastChanged"
            column="lastChanged"/>
    </class>

</hibernate-mapping>


Here is the bean

Code:
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "EMPLOYEE")
public class Employee {
   private int id;   
   private String employee;
   private Date lastChanged;
   
   public Employee(){}
   
   public Employee(String empl){}

   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public String getEmployee() {
      return employee;
   }

   public void setEmployee(String employee) {
      this.employee = employee;
   }

   public Date getLastChanged() {
      return lastChanged;
   }

   public void setLastChanged(Date lastChanged) {
      this.lastChanged = lastChanged;
   }
}



Here is the code withing the servlet.
Code:
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      Session session = HibernateUtil.getSessionFactory().openSession();
        Statistics stats = HibernateUtil.getSessionFactory().getStatistics();
        List list = session.createQuery("from EMPLOYEE m ").list();
      session.close();
   }


Here is the stacktrace
Code:
Oct 1, 2009 1:10:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet TestServlet threw exception
org.hibernate.hql.ast.QuerySyntaxException: EMPLOYEE is not mapped [from EMPLOYEE m ]
   at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: EMPLOYEE is not mapped
PostPosted: Thu Oct 01, 2009 2:02 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi seanc0tter,

have you checked the logs? One of the first things, Hibernate does at start up is reading the mappings. So you should find some info on your EMPLOYEE entity in the logs right after a line that looks like this:
Code:
INFO,org.hibernate.cfg.Environment,main using JDK 1.4 java.sql.Timestamp handling

Look for lines containing
Code:
INFO,org.hibernate.cfg.Configuration
or
Code:
INFO,org.hibernate.cfg.HbmBinder
Is there such a line that your mapping file is read. Is there information in the next lines that Hibernate found the corresponding table?

seanc0tter wrote:
Here is the stacktrace
Code:
Oct 1, 2009 1:10:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet TestServlet threw exception
org.hibernate.hql.ast.QuerySyntaxException: EMPLOYEE is not mapped [from EMPLOYEE m ]
   at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)


Well, that' s hardly a stack trace. That's the top of it. For helping out it would be useful if you'd post the full stack trace that one can possibly see any causes.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: EMPLOYEE is not mapped
PostPosted: Thu Oct 01, 2009 2:27 pm 
Newbie

Joined: Thu Oct 01, 2009 12:58 pm
Posts: 3
Here is some of the log

Code:
INFO: Bytecode provider name : javassist
Oct 1, 2009 1:08:27 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 1, 2009 1:08:27 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Oct 1, 2009 1:08:27 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Oct 1, 2009 1:08:27 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : Employee.hbm.xml
Oct 1, 2009 1:08:27 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.paramountProfressional.Employee -> EMPLOYEE
Oct 1, 2009 1:08:27 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Oct 1, 2009 1:08:27 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Oct 1, 2009 1:08:27 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Oct 1, 2009 1:08:27 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Oct 1, 2009 1:08:27 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test
Oct 1, 2009 1:08:27 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=root, password=****}
Oct 1, 2009 1:08:28 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: MySQL, version: 5.0.51b-community-nt
Oct 1, 2009 1:08:28 PM org.hibernate.cfg.SettingsFactory buildSettings



and all of th stacktrace:
Code:
INFO: Not binding factory to JNDI, no JNDI name configured
Oct 1, 2009 1:10:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet TestServlet threw exception
org.hibernate.hql.ast.QuerySyntaxException: EMPLOYEE is not mapped [from EMPLOYEE m ]
   at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
   at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110)
   at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
   at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:277)
   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:251)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
   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:94)
   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:1650)
   at com.paramountProfressional.TestServlet.doPost(TestServlet.java:42)
   at com.paramountProfressional.TestServlet.doGet(TestServlet.java:33)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
   at java.lang.Thread.run(Unknown Source)



I am also adding the config file:

Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
      <property name="connection.url">jdbc:mysql://localhost/test</property>   
      <property name="connection.username">root</property>   
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>   
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>   
      <property name="connection.password">!QAZxsw2</property>
      <property name="show_sql">true</property>
   
      <mapping resource="Employee.hbm.xml" />
   </session-factory>
</hibernate-configuration>



Thanks!


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: EMPLOYEE is not mapped
PostPosted: Thu Oct 01, 2009 2:40 pm 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi seanc0tter,

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

<snip>

    <class
        name="com.paramountProfressional.Employee"
        table="EMPLOYEE">
</snip>



Is this a typo or did you forget the "." between paramount and Profressional in your mapping file for Employee?

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: EMPLOYEE is not mapped
PostPosted: Thu Oct 01, 2009 3:01 pm 
Newbie

Joined: Thu Oct 01, 2009 12:58 pm
Posts: 3
CU,
It is not a typeo

Code:
package com.paramountProfressional;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "EMPLOYEE")
public class Employee {
   private int id;   
   private String employee;


Sean


Top
 Profile  
 
 Post subject: Re: QuerySyntaxException: EMPLOYEE is not mapped
PostPosted: Sat Oct 03, 2009 11:51 am 
Senior
Senior

Joined: Mon Jul 07, 2008 4:35 pm
Posts: 141
Location: Berlin
Hi Sean,

HQL is object oriented and you have to view it from the Java side. Therefore, you don't query a table but an entity. Try
Code:
List list = session.createQuery("from Employee").list();
Since you didn't specify the entity-name attribute in your <class...> mapping the entity name defaults to the mapped class' name. You can deliberately change that in your mapping.

CU
Froestel

_________________
Have you tried turning it off and on again? [Roy]


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