在做一个j2se的东西 想使用Hibnate方便点,但是在构建完框架进行一个测试的时候,发现不能保存,但可以查询出来数据 public static void main(String[] args) { ApplicationContext conxt = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
BaseDao dao = (BaseDao) conxt.getBean("basedao"); Demp demp = new Demp();
//
demp.setDempNames("企划部");
dao.save(demp);
}我的Spring配置文件,这里只发关键部分,看看我的事物提交有没有问题, 我是重以前项目中扒下来的
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">
PROPAGATION_REQUIRED,-java.lang.Exception
</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
BaseDao dao = (BaseDao) conxt.getBean("basedao"); Demp demp = new Demp();
//
demp.setDempNames("企划部");
dao.save(demp);
}我的Spring配置文件,这里只发关键部分,看看我的事物提交有没有问题, 我是重以前项目中扒下来的
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean> <bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*">
PROPAGATION_REQUIRED,-java.lang.Exception
</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<aop:pointcut id="allManagerMethod" expression="execution(* com.zzq.oa.manager.*.*(..))"/>
这个配置一下看看啊,你的log4j没有配置hibernate的日志没有打出错误
这位仁兄太正确了。。呵呵,,几年前我遇到过一个这样的问题。。
解决方法就是,
hibernate save 后,加一个 flush!
http://topic.csdn.net/u/20090906/11/c991d981-8792-4f69-bbac-83846cbbf3c7.html不知这个连接能不能用。我发的帖。现在已经解决了!不行你搜spring+hibernate能查询但不能插入删除修改 试试
希望对你有帮助