Announcement Announcement Module
No announcement yet.
Problem with Spring 3.0 + Hibernate 3.3: QuerySyntaxException: Class is not mapped Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Spring 3.0 + Hibernate 3.3: QuerySyntaxException: Class is not mapped

    Hello everybody.

    I'm starting a new project using Spring 3.0 and Hibernate 3.3, on MyEclipse 10.

    I built the skeleton web application and deployed on JBoss 6.1, and it works.

    I bult a sample application using Hibernate on MySql, and it works.

    I have problems when moving the Hibernate stuff in the web project.

    I put this in applicationContext.xml

        <bean id="sessionFactory"
        	<property name="dataSource">
        		<ref bean="TestDS" />
        	<property name="hibernateProperties">
        			<prop key="hibernate.dialect">
        			<prop key="hibernate.show_sql">true</prop> 
        	<property name="packagesToScan">
    	    <property name="configurationClass">
        <bean id="TestIssueDAO"
        	<property name="sessionFactory">
        		<ref bean="sessionFactory" />
    This is a snippet of te entity class, generated by the database reverse engineering tools of MyEclipse

    package net.tarrasque.springtest2.db;
    import javax.persistence.AttributeOverride;
    import javax.persistence.AttributeOverrides;
    import javax.persistence.Column;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.Table;
     * TestIssue entity. @author MyEclipse Persistence Tools
    @Table(name = "test_issue", catalog = "coa")
    public class TestIssue implements {
    	// Fields
    	private TestIssueId id;
    From what I can see, all annotations are correct

    The tools also created a DAO, referenced also in applicationContext, where is injected the SessionFactory

    package net.tarrasque.springtest2.db;
    import java.util.List;
    import org.hibernate.LockMode;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.context.ApplicationContext;
     * A data access object (DAO) providing persistence and search support for
     * TestIssue entities. Transaction control of the save(), update() and
     * delete() operations can directly support Spring container-managed
     * transactions or they can be augmented to handle user-managed Spring
     * transactions. Each of these methods provides additional information for how
     * to configure it for the desired type of transaction control.
     * @see net.tarrasque.springtest2.db.TestIssue
     * @author MyEclipse Persistence Tools
    public class TestIssueDAO extends HibernateDaoSupport {
    	private static final Logger log = LoggerFactory
    	public List findAll() {
    		log.debug("finding all TestIssue instances");
    		try {
    			String queryString = "from TestIssue";
    			return getHibernateTemplate().find(queryString);
    		} catch (RuntimeException re) {
    			log.error("find all failed", re);
    			throw re;

    Again, I can't see anything wrong there

    I use the DAO in my simple controller

    package net.tarrasque.springtest2.web;
    import java.util.List;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import net.tarrasque.springtest2.db.TestIssue;
    import net.tarrasque.springtest2.db.TestIssueDAO;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
    public class IssueController extends MultiActionController {
    	private TestIssueDAO testIssueDAO;
    	public ModelAndView list(HttpServletRequest request, HttpServletResponse response) {
    		List<TestIssue> list = testIssueDAO.findAll();
    		ModelMap modelMap = new ModelMap();
    		modelMap.addAttribute("issues", list);
    		return new ModelAndView("IssueList");
    The URL mapping works great, but when I go to localhost:8080/MyApp/issues I only get an error:

    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateQueryException: TestIssue is not mapped [from TestIssue]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: TestIssue is not mapped [from TestIssue]
    I tried all other methods of the DAO, still same error or similar. It looks like the entity class is not parsed at all for annotations. In facts I expected to see some lines in the server console during startup indicating that some annotated classes were found, but I see nothing of this.

    Am I forgetting something? The DB connection is OK, the same DAO and entity class used in the standalone test java app with annotations referenced in hibernate.cfg.xml with

    <mapping class="net.tarrasque.springtest.db.TestIssue" />


    I really have no other ideas...

  • #2
    Can you try removing this as it should not be required:

    <property name="configurationClass">
    Not sure that having this in place would cause this issue however.

    Although is seems possible given the Javadoc.
    Last edited by alanhay; Apr 18th, 2013, 10:07 AM.


    • #3
      No, that's not the problem. I had not that property set at the beginning, it's part of the tests I'm doing to make it work.

      I just tried removing it, and the result is unfortunately the same.

      I also tried explicitly setting the annotatedClass properties

          	<property name="annotatedClasses">
      And even pointing to a small external Hibernate configuration file, like in the test project without Spring

      	    <property name="configLocation">
      where src/hibernate.cfg.xml contains:

      <?xml version='1.0' encoding='UTF-8'?>
      <!DOCTYPE hibernate-configuration PUBLIC
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
              <mapping class="net.tarrasque.springtest2.db.TestIssue"/>
      But nothing changes.