Configuration config = new Configuration().configure(); 
SessionFactory sessionFactory = config.buildSessionFactory(); 
Session session = sessionFactory.openSession(); 
Guestbook gb = new Guestbook(); 
gb.setName("sdfsdfsd"); 
gb.setEmail("sdfsdfsf"); 
gb.setPhone("sdfsdfsdf"); 
gb.setTitle("sdfsdfsdf"); 
gb.setContent("asdasdasd"); 
gb.setCreatedTime(new Date()); 
Transaction transaction = session.beginTransaction(); 
session.save(gb); 
transaction.commit(); 
session.close();
配置文件 各种都没有问题,只是在插入中文数据的时候就会报 
“Could not synchronize database state with session 
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update”的错误。。反复试验不得其解 希望各位大人教教小弟~ 
下面的是Guestbook.hbm.xml:(是用hibernate生成并自己做了修改的) 
<hibernate-mapping> 
    <class name="com.java.yz.hibernate.Guestbook" table="GUESTBOOK" schema="SCOTT"> 
        <id name="id" type="java.lang.Integer"> 
            <column name="ID"/> 
            <generator class="sequence" > 
            <param name="sequence">gb_seq </param> 
            </generator> 
        </id> 
        <property name="name" type="java.lang.String"> 
            <column name="NAME" length="40" not-null="true" /> 
        </property> 
        <property name="email" type="java.lang.String"> 
            <column name="EMAIL" length="100" not-null="true" /> 
        </property> 
        <property name="phone" type="java.lang.String"> 
            <column name="PHONE" length="20" /> 
        </property> 
        <property name="title" type="java.lang.String"> 
            <column name="TITLE" length="100" not-null="true" /> 
        </property> 
        <property name="content" type="java.lang.String"> 
            <column name="CONTENT" length="4000" /> 
        </property> 
        <property name="createdTime" type="java.util.Date"> 
            <column name="CREATED_TIME" length="7" not-null="true" /> 
        </property> 
    </class> 
</hibernate-mapping>

解决方案 »

  1.   

    你先试试,用hibernate生成的sql语句,能不能执行成功呢?
      

  2.   

    检查下数据库中的表结构,是否插入中文的那个字段数据类型不是nvarchar2,还有插入时的字符集,是否和数据库服务器NLS对应,
    如果不是最好统一下三个地方的字符集:
    数据库UTF-8
    代码编辑器字符集UTF-8
    页面字符集UTF-8
      

  3.   

    字段类型都是varchar2 设置的长度也都绝对够字符集不会设=。= 
    不过,原来直接用sqlplus操作oracle的时候插入中文都米有问题。。
    但是在myeclipse上测试插入用hibernate向数据库插入数据就不行。。
      

  4.   

    在MyEclipse里 我看也是utf-8的设置。。
      

  5.   

    原来是oracle驱动的问题!!!大爷的   真没细琢磨过 ojdbc14和classes12的区别  恶心我两天啦!!!!!!!!