使用Hibernate向数据库中添加数据
2012-07-30 10:49
369 查看
技术:三大框架
错误信息:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
错误原因:新建的service类和配置文件中配置的service类的路径不一致
<!-- 事务的配置 --> <!-- sessionFactory 为自己配置 sessionFactory 的 bean--> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:config> <!-- execution(public * *.*.*..*.*(..)) 为自己项目中操作数据库中的方法 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> <!-- 可以设置两个pointcut,id不能相同 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <!-- 同时将第二个pointcut 也关联 txAdvice --> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- name 为 方法名 --> <tx:method name="**" read-only="true" /> <tx:method name="**" propagation="REQUIRED" /> </tx:attributes> </tx:advice>
错误信息:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
错误原因:新建的service类和配置文件中配置的service类的路径不一致
<!-- 事务的配置 --> <!-- sessionFactory 为自己配置 sessionFactory 的 bean--> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:config> <!-- execution(public * *.*.*..*.*(..)) 为自己项目中操作数据库中的方法 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> <!-- 可以设置两个pointcut,id不能相同 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <!-- 同时将第二个pointcut 也关联 txAdvice --> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- name 为 方法名 --> <tx:method name="**" read-only="true" /> <tx:method name="**" propagation="REQUIRED" /> </tx:attributes> </tx:advice>
<!-- 事务的配置 --> <!-- sessionFactory 为自己配置 sessionFactory 的 bean--> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <aop:config> <!-- execution(public * *.*.*..*.*(..)) 为自己项目中操作数据库中的方法 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> <!-- 可以设置两个pointcut,id不能相同 --> <aop:pointcut id="**" expression="execution(public * *.*.*..*.*(..))" /> <!-- 同时将第二个pointcut 也关联 txAdvice --> <aop:advisor pointcut-ref="**" advice-ref="txAdvice" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- name 为 方法名 --> <tx:method name="**" read-only="true" /> <tx:method name="**" propagation="REQUIRED" /> </tx:attributes> </tx:advice>
相关文章推荐
- hibernate 使用注解 查询和添加对象到数据库没有反应
- 数据库数据添加到TextView详解(limite参数如何使用)
- 使用Greendao进行批量添加数据(Android Studio读取assets下的数据库文件)
- Thinkphp框架中使用数据对象自动处理添加数据库数据时,关于在数据库表中添加新列时出现新列的数据添加不上去?
- 使用Hibernate插入数据后数据库没有记录的解决方法
- 使用MySQL Workbench建立数据库,建立新的表,向表中添加数据
- CoreData初始识 使用CoreData为数据库添加数据
- 巧妙使用JQuery Clone 添加多行数据,并更新到数据库
- 使用MySQL Workbench建立数据库,建立新的表,向表中添加数据
- appserv中使用mysql时向数据库中添加数据时报错
- 使用hibernate查询时,查询的数据和数据库的不一样问题
- 使用C#类向数据库添加数据的例子源码
- 小学生之Hibernate插入数据修改数据使用数据库默认值的实现
- 使用RESTful Jersey框架搭建WebService,Hibernate框架访问数据库,MySQL存储数据
- 使用hibernate插入数据对象不成功,且数据库自增长
- 巧妙使用JQuery Clone 添加多行数据,并更新到数据库
- java 演示使用jdbc-odbc桥连接的方式操作数据库 向数据库中添加数据
- MapX使用数据库数据添加专题图(系列之三)
- listview动态添加数据,使用sqlite对本地数据库增删改查
- Thinkphp使用create()无法向数据库添加数据