hibernate + oracle

 

 

出现问题

 

2010-09-17 21:02:07,969  WARN (org.hibernate.util.JDBCExceptionReporter:77) - SQL Error: 942, SQLState: 42000
2010-09-17 21:02:07,969 ERROR (org.hibernate.util.JDBCExceptionReporter:78) - ORA-00942: 表或视图不存在

解决办法

http://blueart.iteye.com/blog/230203

 

后修改如下

 

<hibernate-configuration>

      <session-factory>
           
            
             <property name="show_sql">false</property>
            
             <property name="dialect"> org.hibernate.dialect.Oracle9Dialect  </property>
            
             <!-- org.hibernate.dialect.Oracle11gDialect -->
          
            
             <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver </property>

             <property name="connection.url">jdbc:oracle:thin:@localhost:1521/org.macau.rssnews</property>

             <property name="connection.username">system</property>

             <property name="connection.password">xxxxxxx</property>     

             <mapping resource="Feed.hbm.xml" />
             <mapping resource="News.hbm.xml" />
      </session-factory>

</hibernate-configuration>

 

 

 <class name="Feed" table="feed" schema="org.macau.rssnews">
        <id name="id" column="id">
   <generator class="sequence">    
       <param name="sequence">TABLE_ID_SEQ</param>
   </generator>   
  </id>
  <property name="title" column="title"  />
  <property name="url" column="url" not-null="true"/>
  <property name="publishedDate" column="publishedDate"></property>

  </class>

 

 

但还是错误:

 

2010-09-17 21:07:21,619  WARN (org.hibernate.util.JDBCExceptionReporter:77) - SQL Error: 933, SQLState: 42000
2010-09-17 21:07:21,619 ERROR (org.hibernate.util.JDBCExceptionReporter:78) - ORA-00933: SQL 命令未正确结束

 

 

经过将hibernate 的log4j threshold 设定为 dbug。可以看到最后从 程序中 的HQL 语句最终生成的SQL语句

 

 

 String hql = "from Feed as f";

 

select feed0_.id as id0_, feed0_.title as title0_, feed0_
.url as url0_, feed0_.publishedDate as publishe4_0_ from org.macau.rssnews.feed feed0_

 

在查询器中一验证,问题在于上面生成的语句部分: org.macau.rssnews.feed

 

 

 

*****************

但是如果数据库是用远程的服务器,问题没不出现。 最有可能的原因是本地服务器的链接有问题 

 

 

今天终于找到了原因了,不是由于上面的原因造成的,是因为先前是在 sys用户权限下创建的两个表,而程序中使用的是登录帐号是 system, 各自的表空间和权限都不一样,所以造成表不存在的错误

你可能感兴趣的:(oracle,sql,Hibernate,log4j,jdbc)