在applicationContext.xml中配置如下
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property></bean>
在dao实现中调用 this.hibernateTemplate.save(entity);控制台打印如下信息
Hibernate: select sshproduct0_.id as id2_0_, sshproduct0_.category_id as category2_2_0_, sshproduct0_.name as name2_0_, sshproduct0_.price as price2_0_, sshproduct0_.mounts as mounts2_0_, sshproduct0_.sellMounts as sellMounts2_0_ from hibernate.ssh_product
sshproduct0_ where sshproduct0_.id=?
Hibernate: select sshorderit0_.prouct_id as prouct3_1_, sshorderit0_.id as id1_, sshorderit0_.id as id3_0_, sshorderit0_.orders_id as orders2_3_0_, sshorderit0_.prouct_id as prouct3_3_0_, sshorderit0_.mounts as mounts3_0_ from hibernate.ssh_orderitem sshorderit0_
where sshorderit0_.prouct_id=?
Hibernate: select max(id) from ssh_orders
Hibernate: select max(id) from ssh_orderitem
Hibernate: insert into hibernate.ssh_orders (user_id, orderId, id) values (?, ?, ?)
Hibernate: insert into hibernate.ssh_orderitem (orders_id, prouct_id, mounts, id) values (?, ?, ?, ?)
Hibernate: update hibernate.ssh_product set category_id=?, name=?, price=?, mounts=?, sellMounts=? where id=?
但是数据库中的数据并没有更新,后来在hibernate.cfg.xml中配置如下一句话:<property name="connection.autocommit">true</property>
终于成功了