Hibernate用户缺少权限或对象未找到错误

时间:2013-02-18 15:01:05

标签: java hibernate

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

时,我得到了查询

休眠:选择ifmain0_.IF_ID作为IF1_0_,ifmain0_.IF_NAME作为IF2_0_来自IF_MAIN ifmain0 _

但在那之后我得到了上述错误。所以我删除了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:文件:C:/用户/ 298637 /样品; hsqldb.lock_file =假         org.hibernate.dialect.HSQLDialect         SA         SA         1         线         org.hibernate.cache.NoCacheProvider         真正         没有              

映射文件是

<?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时,我收到此错误

0 个答案:

没有答案