Results 1 to 6 of 6

Thread: table is not mapped exception

  1. #1
    Join Date
    Oct 2004
    Location
    Germany, Mainz
    Posts
    19

    Default table is not mapped exception

    Hi,
    I got a quite curious problem. I wrote a DAOTest to check if my DAO implementation works fine.
    Code:
    Code:
    /**
    *	23.05.2005
    *	11:52:05
    * 	johannes.hiemer
    *  	SystemTypeDAOTest.java
    */
    package itecon.dao.hibernate.test;
    
    import itecon.bo.dao.ISystemtypeDAO;
    import itecon.bo.model.Systemtype;
    import junit.awtui.TestRunner;
    
    import org.apache.log4j.Logger;
    
    /**
     * @author johannes.hiemer
     *
     * ITecon Dell Call System 
     */
    public class SystemTypeDAOTest extends BaseDAOTestCase {
    
        private Systemtype stype;
        private ISystemtypeDAO stypeDAO;
        
        protected void setUp() throws Exception {
            log = Logger.getLogger(SystemErrorDAOTest.class.getName());
            stypeDAO = (ISystemtypeDAO) ctx.getBean("systemTypeDAO");
        }
        
        protected void tearDown() throws Exception {
            stypeDAO = null;
        }
        
        public static void main(String args []) {
            TestRunner.run(SystemTypeDAOTest.class);
        }
        
        public Systemtype createSystemType() {
            stype = new Systemtype();
            stype.setStprice("40,0€");
            stype.setSttype("Server");
            return stype;
        }
        
        public void testAddAndRemoveSystemType() {
            createSystemType();
            log.info(stype);
    
            stypeDAO.saveSystemtype(stype);
    
            assertTrue("primary key assigned", stype.getStid() != null);
            log.info(stype);
            assertTrue(stype.getSttype() != null);
            
            stypeDAO.getSystemtype(stype.getStid());
            
            assertTrue("primary key not assigned",  stype.getStid() != null);
        }
    }
    When I run my DAOTest it works. Adding one line results in a crash, which origin is not understandable for me.
    Code:
            log.info(stypeDAO.getSystemtypes());
    When I add this line behind:
    stypeDAO.saveSystemtype(stype);

    I a get an exception: systemtype is not mapped.

    Stacktrace:
    Code:
    org.springframework.orm.hibernate3.HibernateQueryException: systemtype is not mapped. [from systemtype]; nested exception is org.hibernate.hql.ast.QuerySyntaxError: systemtype is not mapped. [from systemtype]
    org.hibernate.hql.ast.QuerySyntaxError: systemtype is not mapped. [from systemtype]
    	at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:196)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
    	at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:425)
    	at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:880)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:830)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
    	at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:749)
    	at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:311)
    	at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:740)
    	at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:732)
    	at itecon.bo.dao.hibernate.SystemtypeDAOHibernate.getSystemtypes(SystemtypeDAOHibernate.java:42)
    	at itecon.dao.hibernate.test.SystemTypeDAOTest.testAddAndRemoveSystemType(SystemTypeDAOTest.java:50)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at junit.framework.TestCase.runTest(TestCase.java:154)
    	at junit.framework.TestCase.runBare(TestCase.java:127)
    	at junit.framework.TestResult$1.protect(TestResult.java:106)
    	at junit.framework.TestResult.runProtected(TestResult.java:124)
    	at junit.framework.TestResult.run(TestResult.java:109)
    	at junit.framework.TestCase.run(TestCase.java:118)
    	at junit.framework.TestSuite.runTest(TestSuite.java:208)
    	at junit.framework.TestSuite.run(TestSuite.java:203)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by:  systemtype is not mapped.
    	at org.hibernate.hql.ast.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:85)
    	at org.hibernate.hql.ast.FromElementFactory.addFromElement(FromElementFactory.java:77)
    	at org.hibernate.hql.ast.FromClause.addFromElement(FromClause.java:67)
    	at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:217)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2830)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
    	at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
    	at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
    	... 27 more
    But what I am wondering is, that the insert in the line before (stypeDAO.saveSystemtype(stype);) works, but the complete select from the database doesn't. I checked if the Database got the inserted values. What's wrong with my implementation/DAOTest?

    I hope you can help me.

    Thanks a lot

    Johannes

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Can you post your mappings.

  3. #3
    Join Date
    Oct 2004
    Location
    Germany, Mainz
    Posts
    19

    Default

    Hi,
    here it is:
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http&#58;//hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
    <!-- 
            Auto-generated mapping file from
            the hibernate.org cfg2hbm engine
    -->
      <class name="itecon.bo.model.Systemtype" table="SYSTEMTYPE" schema="DELL">
        <id name="Stid" type="java.lang.Long">
          <column name="STID" scale="22" precision="0" not-null="true" unique="true" sql-type="NUMBER" />
          <generator class="native" />
        </id>
        <property name="Sttype" type="java.lang.String">
          <column name="STTYPE" scale="100" precision="0" not-null="true" sql-type="VARCHAR2" />
        </property>
        <property name="Stprice" type="java.lang.String">
          <column name="STPRICE" scale="100" precision="0" not-null="true" sql-type="VARCHAR2" />
        </property>
      </class>
    </hibernate-mapping>
    Thanks a lot for your help.

    Bye Johannes

  4. #4
    Join Date
    Oct 2004
    Location
    Germany, Mainz
    Posts
    19

    Default

    Hi,
    to provide some help for people who got stuck in the same
    situation, remember that "from Table" is case sensitive.

    That was my fault.

    Bye Johannes

  5. #5
    Join Date
    Nov 2007
    Posts
    1

    Thumbs up table is not mapped exception

    Hi all,

    I was faced with the same problem too. I have a table named PRODUCTS and class Product. I got the feeling it is because of the limitation of Hibernate in translating table name to the right class. It does not even able to translate the table alias to the class. For example: the piece of the SQL statement "from PRODUCTS as Product" to the Product class.

    If you are using HibernateTemplate from org.springframework.orm.hibernate3, then I guess you have no choice to sync the table and class names.

    The solutions that I found are as follows:
    Solution A: use the Session.createCriteria()

    Code:
    List products = sess.createCriteria(Product.class)
    .add( Restrictions.in( "name", new String[] { "Lamp", "Table", "Chair" } ) )
    .list();
    I think this solution is good when you need to query data only from a single table.

    Solution B: use the Session.createSQLQuery()

    Code:
    List products = getSession().createSQLQuery("SELECT * FROM Products").addEntity(Product.class).list();
    Cheers,
    JR

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    I think you miss the points of hibernate... Hibernate uses OBJECTS so if you have a class Product mapped to a table PRODUCTS your query is

    Code:
    from Product
    In HQL you work with objects not with tables!

    So in your case your select hql for all the stuff would read

    Code:
    from Systemtype
    instead of

    Code:
    from systemtype
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Similar Threads

  1. Context initialization failed
    By kanonmicke in forum Container
    Replies: 7
    Last Post: Sep 29th, 2005, 12:35 AM
  2. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  3. Replies: 0
    Last Post: Jul 11th, 2005, 05:49 PM
  4. Replies: 2
    Last Post: May 13th, 2005, 05:42 AM
  5. Replies: 3
    Last Post: Nov 8th, 2004, 07:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •