日期:2014-05-20  浏览次数:20711 次

Spring Hibernate save无法插入到数据库中(上网搜过了,但是没有找到解决的办法)
我的Spring配置文件如下:


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>

<property name="url">
<value>jdbc:mysql://localhost:3306/store?useUnicode=true&amp;characterEncoding=UTF-8</value>
</property>

<property name="username">
<value>root</value>
</property>

<property name="password">
<value>****</value>
</property>
</bean>


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>

<property name="mappingResources">
<list>
<value>com/**/bean/ReceUnit.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>

<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
</bean>


<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>


<bean id="ReceUnitDAO" class="com.**.dao.impl.ReceUnitDAOImpl"
scope="singleton">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>


<bean id="receUnitServiceTarger" class="com.**.service.impl.ReceUnitServiceImpl">
<property name="receUnitDAO">
<ref bean="ReceUnitDAO" />
</property>
</bean>

<bean id="receUnitService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="target" ref="receUnitServiceTarger"></property>
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop><!-- PROPAGATION_REQUIRED:如果存在一个事务就使用这个事务,否则开启新的事务 -->
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean id="addReceUnit" class="com.**.action.receunit.AddReceUnit">
<property name="service" ref="receUnitService"></property>
</bean>

Bean如下:
public class ReceUnit {
private Integer id;
private String index;
private String name;
  setter()&&getter();
}



Action(属性驱动)如下:

public class AddReceUnit extends ActionSupport {
private String index;
private String name;
private ReceUnitService service;
  setter()&&getter();
   
  @Override
public String execute() throws Exception {

  ReceUnit ru = new ReceUnit();
  //主键id在hbm中设置为自增类型