hibernate常见异常

1. ClassNotFoundException: org.hibernate.hql.ast.HqlToken

    解决办法:在hibernate配置文件中加入<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

2.unknown Oracle major version[0]

java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

 

3.Session session= new Configuration().configure().buildSessionFactory()

.openSession();

少HIBERNATE JAR 包,hibernate jar包导入时,少导入了一个。

 

4.        Upload upload =new Upload();

             upload.setContext(sb.toString());

             upload.setFilename(fname);

             upload.setId(10);

             /**

             *数据库操作

              **/

             Session session =new Configuration().configure().buildSessionFactory().openSession();

            Transaction tran = session.beginTransaction();

            session.save(upload);

           tran.commit();

            session.close();

 

报错:org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

Exlipse断点发现在commit时出错,在网上也找了很多关于此类问题的解决办法,很多都没用上,最终换了一个oracle的驱动jar包问题消失。

 

5. 我做的是ssh。我把hibernate放在了spring中进行管理,在MyEclipse中通过hibernate映射表的时候总是报错unknown oracle majoy version[0] 

<?xml version="1.0" encoding="UTF-8"?>

<beans

    xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

     <bean id="DataSource"

       class="org.springframework.jndi.JndiObjectFactoryBean">

       <property name="jndiName" value="jndi"></property>

    </bean>

    <bean id="sid"

       class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

       <property name="dataSource">

           <ref bean="DataSource" />

       </property>

       <property name="hibernateProperties">

           <props>

              <prop key="hibernate.dialect">

                  org.hibernate.dialect.Oracle9Dialect

              </prop>

           </props>

       </property>

    </bean></beans>

你可能感兴趣的:(oracle,Hibernate,MyEclipse,session,upload,jar)