日期:2014-05-17  浏览次数:20833 次

用spring的HibernateTemplate的save()方法不能插入数据
本帖最后由 scriptguy 于 2010-05-19 19:35:05 编辑 在别的项目中可以直接使用HibernateTemplate的save()来持久化数据
但是现在遇到了问题:
使用HibernateTemplate的save()有hibernate插入语句:Hibernate: insert into T_Orgnization (name, sn, description, pid) values (?, ?, ?, ?)
可是查看数据库却没有相应的数据,太奇怪了!!!!!

希望高手给予解答!


DAO类:

package com.scriptguy.oa.manager.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.scriptguy.oa.manager.OrgManager;
import com.scriptguy.oa.model.Orgnization;

public class OrgManagerImpl extends HibernateDaoSupport implements OrgManager {

public void addOrg(Orgnization org, int parentId) {
this.getHibernateTemplate().save(org);
System.out.println("test");

}
}


hibernate.cfg.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1/oa</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">scriptguy</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.current_session_context_class">thread</property> 
    <mapping resource="com/scriptguy/oa/model/Orgnization.hbm.xml"/>
    <mapping resource="com/scriptguy/oa/model/Person.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


spring配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<va