Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: TESTING is not mapped [FROM TESTING]

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: TESTING is not mapped [FROM TESTING]

I am very new to Hibernate, just trying to execute a sample app to test this and understand how it works.package main;

POJO class:

package main;

public class Testing {

    private int id;
    public int getId() {
        return id;
    }

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


    public String getName() {
        return name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public int getSal() {
        return Sal;
    }


    public void setSal(int sal) {
        Sal = sal;
    }


    private String name;
    private int Sal;


    public Testing(){

    }
    public Testing(int id_val, String namedetails, int Sal_details)
    {
        this.name = namedetails;
        this.id = id_val;
        this.Sal = Sal_details;
    }
}


Class to test the hibernate example,

    package main;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;


public class HiberTest {

    @SuppressWarnings("rawtypes")
    public static void main (String args[]){

        SessionFactory factory;
            try{
                factory = new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) 
        {
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);          
        }

            Transaction tx = null;

            Session ss = factory.openSession();
            tx = ss.beginTransaction();

            //Testing testOne = new Testing(8,"Naani",4500);

            List test_list = ss.createQuery("FROM TESTING").list(); 

            //int test_one = (Integer)ss.save(testOne);

            for (Iterator iter=test_list.iterator();iter.hasNext();)
            {
                Testing test = (Testing) iter.next();
                System.out.println("ID:\t"+ test.getId());
                System.out.println("Name:\t"+ test.getName());
                System.out.println("Salary:\t"+ test.getSal());
                System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%");
            }           
            ss.close();
    }
}


config files:


    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 26, 2013 1:11:02 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="main.Testing" table="TESTING">
        <id name="id" type="int">
            <column name="COL1" />
            <generator class="assigned" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="COL2" />
        </property>
        <property name="Sal" type="int">
            <column name="COL3" />
        </property>
    </class>
</hibernate-mapping>


    <?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3//EN" 
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory name="">
  <property name="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver</property>
  <property name="hibernate.connection.password"/>
  <property name="hibernate.connection.url">jdbc:hsqldb:MyDB</property>
  <property name="hibernate.connection.username">sa</property>
  <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
  <mapping resource="Testing.hbm.xml"/>  
 </session-factory>
</hibernate-configuration>

    Exception:

   `15 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
31 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
31 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
62 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
62 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
125 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : Testing.hbm.xml
172 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: main.Testing -> TESTING
172 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: 
218 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using Hibernate built-in connection pool (not for production use!)
218 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hibernate connection pool size: 20
218 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocommit mode: false
218 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.hsqldb.jdbc.JDBCDriver at URL: jdbc:hsqldb:MyDB
218 [main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=sa, password=****}
672 [main] INFO org.hibernate.cfg.SettingsFactory - RDBMS: HSQL Database Engine, version: 2.2.9
672 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC driver: HSQL Database Engine Driver, version: 2.2.9
687 [main] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.dialect.HSQLDialect
687 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Using default transaction strategy (direct JDBC transactions)
687 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
687 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeCompletion(): disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end of transaction: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
687 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for versioned data: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Connection release mode: auto
687 [main] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
687 [main] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary key: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Order SQL inserts for batching: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
687 [main] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
687 [main] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions: {}
687 [main] INFO org.hibernate.cfg.SettingsFactory - JPA-QL strict compliance: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory
687 [main] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal puts: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache entries: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
687 [main] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
687 [main] INFO org.hibernate.cfg.SettingsFactory - Named query checking : enabled
718 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
843 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Factory name: 
843 [main] INFO org.hibernate.util.NamingHelper - JNDI InitialContext properties:{}
843 [main] WARN org.hibernate.impl.SessionFactoryObjectFactory - Could not bind factory to JNDI
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
    at javax.naming.InitialContext.getNameParser(Unknown Source)
    at org.hibernate.util.NamingHelper.bind(NamingHelper.java:75)
    at org.hibernate.impl.SessionFactoryObjectFactory.addInstance(SessionFactoryObjectFactory.java:113)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:338)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
    at main.HiberTest.main(HiberTest.java:18)
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: TESTING is not mapped [FROM TESTING]
    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 main.HiberTest.main(HiberTest.java:32)`


--------------------------------------------------------------------------------------

TestDB.java, was used to test the DB connnection using SQL statements, but its failing to connect to HSQL database.

    package main;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestDB {
    public static void main (String args[]) throws SQLException, Exception
    {
        Connection conn;
        Class.forName("org.hsqldb.jdbc.JDBCDriver");
        conn = DriverManager.getConnection("jdbc:hsqldb:MyDB","sa","");
        Statement st = conn.createStatement();
        st.executeUpdate("INSERT INTO PUBLIC.TSET_TABLE (COL1, COL2,COL3) VALUES (15 ,'GURU',560)");
        ResultSet rs = st.executeQuery("select * from PUBLIC.TESTING");
                // st.executeQuery("CREATE TABLE PUBLIC.TEST_TABLE (COL1 INTEGER NOT NULL, COL2 CHAR(25), COL3 integer, COL4 DATE, primary key (COL1))");       
        while(rs.next())
        {
            System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getInt(3));            
        }
    }
}

couldn't connect to tDB using, SQL statements.

Exception in thread "main" java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: TESTING
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
    at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
    at main.TestDB.main(TestDB.java:15)
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: TESTING
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.error.Error.error(Unknown Source)
    at org.hsqldb.SchemaManager.getTable(Unknown Source)
    at org.hsqldb.ParserDQL.readTableName(Unknown Source)
    at org.hsqldb.ParserDQL.readRangeVariableForDataChange(Unknown Source)
    at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
    at org.hsqldb.Session.executeDirectStatement(Unknown Source)
    at org.hsqldb.Session.execute(Unknown Source)
    ... 3 more



Data in DB:

I have an HSQL DB configured and the data in it,

 COL1 COL2  COL3 
 ---- ----- ---- 
 10   MUNI  560
 11   Naani 560


Can someone please help me to get this fixed??

Thanks in advance!! 
Muni
View Answers

April 29, 2013 at 3:15 PM

Configuration files:

org.hsqldb.jdbc.JDBCDriver jdbc:hsqldb:MyDB sa org.hibernate.dialect.HSQLDialect


April 29, 2013 at 3:16 PM

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 26, 2013 1:11:02 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="main.Testing" table="TESTING">
        <id name="id" type="int">
            <column name="COL1" />
            <generator class="assigned" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="COL2" />
        </property>
        <property name="Sal" type="int">
            <column name="COL3" />
        </property>
    </class>
</hibernate-mapping>


    <?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3//EN" 
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory name="">
  <property name="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver</property>
  <property name="hibernate.connection.password"/>
  <property name="hibernate.connection.url">jdbc:hsqldb:MyDB</property>
  <property name="hibernate.connection.username">sa</property>
  <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
  <mapping resource="Testing.hbm.xml"/>  
 </session-factory>
</hibernate-configuration>









Related Tutorials/Questions & Answers:
Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: TESTING is not mapped [FROM TESTING]
Exception in thread "main" java.lang.ClassCastException
Advertisements
Exception in thread "main" java.lang.ClassCastException
exception in thread main java.lang.unsupportedclassversionerror in ubuntu
exception in thread main java.lang.unsupportedclassversionerror in eclipse
exception in thread main while running servlet
exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
exception in thread main java.lang.unsupportedclassversionerror unsupported major.minor version 50.0 - Java Beginners
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
Main Thread and Child Thread
How to Differenciate Main Thread and Child Thread in Java
difference between main thread and child thread?
Exception in thread
Exception in thread
Exception in thread
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Exception in Thread
how to solve the nullPointer Exception in main - Java Beginners
Java Exception Thread
no action mapped for action - Struts
ModuleNotFoundError: No module named 'mapped'
ModuleNotFoundError: No module named 'mapped'
ModuleNotFoundError: No module named 'mapped'
Hibernate error class is not mapped
ModuleNotFoundError: No module named 'mapped-config'
ModuleNotFoundError: No module named 'mapped-enum'
ModuleNotFoundError: No module named 'mapped-enum'
ModuleNotFoundError: No module named 'mapped-config'
ModuleNotFoundError: No module named 'mapped-enum'
ModuleNotFoundError: No module named 'mapped-config'
MAin error
Hibernate table not mapped error - solution
ModuleNotFoundError: No module named 'remove_qcfailed_mapped'
ModuleNotFoundError: No module named 'django-mapped-fields'
ModuleNotFoundError: No module named 'convert-mapped-json'
ModuleNotFoundError: No module named 'convert-mapped-json'
ModuleNotFoundError: No module named 'convert-mapped-json'
Java Sleep Thread
if i run this prog, i got exeption in thread "main" java.lang.ArrayIndexOutOfBoundsException:0 at Maxof2.main(Maxof2.java:9), whats the resolution for ths?
java exception
Thread in java
Java Thread Join
Unhandled Exception in Thread
Jfree exception
Jfree exception
main method
main method
Java Thread : isAlive() method
Java Thread : getState() Example
java Thread

Ads