1

我创建了一个java应用程序,它将从表中选择ceratin值并使用hibernate打印它。我使用HSQLDb作为后端。但执行后我收到错误用户缺少权限或找不到对象:但我正在获取查询当我第一次执行时

休眠:从 IF_MAIN ifmain0_ 中选择 ifmain0_.IF_ID 作为 IF1_0_,ifmain0_.IF_NAME 作为 IF2_0_

但在那之后我得到了上述错误。所以我删除了 sample.lck 文件,再次执行两次后我得到了同样的错误

错误 org.hibernate.util.JDBCExceptionReporter - 用户缺少权限或找不到对象:IF_MAIN

org.hibernate.exception.SQLGrammarException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2545)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at org.mock.Mainclass.listNAMES(Mainclass.java:31)
    at org.mock.Mainclass.main(Mainclass.java:22)
Caused by: java.sql.SQLException: user lacks privilege or object not found: IF_MAIN
    at org.hsqldb.jdbc.Util.sqlException(Util.java:224)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(JDBCPreparedStatement.java:3885)
    at org.hsqldb.jdbc.JDBCConnection.prepareStatement(JDBCConnection.java:641)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1700)
    at org.hibernate.loader.Loader.doQuery(Loader.java:801)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2542)
    ... 9 more
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: IF_MAIN
    at org.hsqldb.error.Error.error(Error.java:77)
    at org.hsqldb.SchemaManager.getTable(SchemaManager.java:685)
    at org.hsqldb.ParserDQL.readTableName(ParserDQL.java:5297)
    at org.hsqldb.ParserDQL.readTableOrSubquery(ParserDQL.java:1662)
    at org.hsqldb.ParserDQL.XreadTableReference(ParserDQL.java:1074)
    at org.hsqldb.ParserDQL.XreadFromClause(ParserDQL.java:1061)
    at org.hsqldb.ParserDQL.XreadTableExpression(ParserDQL.java:996)
    at org.hsqldb.ParserDQL.XreadQuerySpecification(ParserDQL.java:990)
    at org.hsqldb.ParserDQL.XreadSimpleTable(ParserDQL.java:974)
    at org.hsqldb.ParserDQL.XreadQueryPrimary(ParserDQL.java:903)
    at org.hsqldb.ParserDQL.XreadQueryTerm(ParserDQL.java:869)
    at org.hsqldb.ParserDQL.XreadQueryExpressionBody(ParserDQL.java:848)
    at org.hsqldb.ParserDQL.XreadQueryExpression(ParserDQL.java:822)
    at org.hsqldb.ParserDQL.compileCursorSpecification(ParserDQL.java:5449)
    at org.hsqldb.ParserCommand.compilePart(ParserCommand.java:133)
    at org.hsqldb.ParserCommand.compileStatement(ParserCommand.java:63)
    at org.hsqldb.Session.compileStatement(Session.java:906)
    at org.hsqldb.StatementManager.compile(StatementManager.java:335)
    at org.hsqldb.Session.execute(Session.java:1009)
    at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(JDBCPreparedStatement.java:3882)





My hibernate config file is 

org.hsqldb.jdbcDriver jdbc:hsqldb:file:C:/Users/298637/SAMPLE;hsqldb.lock_file=false org.hibernate.dialect.HSQLDialect sa sa 1 线程 org.hibernate.cache.NoCacheProvider true none

映射文件是

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
 "-//Hibernate/Hibernate Mapping DTD//EN"
 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping package="org.mock">
   <class name="IFMAIN" table="IF_MAIN ">
      <meta attribute="class-description">
         This class contains the employee detail. 
      </meta>
      <id name="number" type="string" column="IF_ID">
         <generator class="native"/>
      </id>
      <property name="name" column="IF_NAME" type="string"/>
   </class>
</hibernate-mapping>

Pojo CLASS

public class IFMAIN {
    private String number;
    private String name ;
    public IFMAIN()
    {

    }
    public String getNumber() {
        return number;
    }
    public void setNumber(String number) {
        this.number = number;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

}

主班

import java.util.Iterator;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Mainclass {
     private static SessionFactory factory; 
       public static void main(String[] args) {
          try{
             factory = new Configuration().configure().buildSessionFactory();
          }catch (Throwable ex) { 
             System.err.println("Failed to create sessionFactory object." + ex);
             throw new ExceptionInInitializerError(ex); 
          }
          Mainclass ME = new Mainclass();
          ME.listNAMES();
}


public void listNAMES( ){
   Session session = factory.openSession();
   Transaction tx = null;
   try{
      tx = session.beginTransaction();
      List sample = session.createQuery("FROM IFMAIN").list();
      int i=0;
      for (Iterator iterator = sample.iterator(); iterator.hasNext();){
         IFMAIN count = (IFMAIN) iterator.next(); 
         System.out.println("SITE CODE: " + count.getNumber()); 
         System.out.println("SITE DESCRIPTION: " + count.getName());  
      }

      tx.commit();
   }catch (HibernateException e) {
      if (tx!=null) tx.rollback();
      e.printStackTrace(); 
   }finally {
      session.close(); 
   }
}
}

谁能告诉我为什么我会收到这个错误。我尝试使用其他数据库,如 mysql 和 oracle 10g。我能够连接并获得结果,但是当我使用 HSQL Db 时出现此错误

4

0 回答 0