关于hibernate中插入数据报read-only mode只读模式错误

项目中有时候会遇到插入数据到表中去报错只读模式

org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

这种错误如果之前一直没有,且未曾修改app-config-context.xml配置文件,突然就出现了此类问题,一般都是由于自己开发中方法名取名和配置文件中配置项冲突

例如方法名取名为  public void getsomething(){},若此方法中有事务提交(增、删、改)表操作,将会报上述错误,因为配置项中已经配置get*为只读模式,故只需将自己方法名中的get去掉或替换即可。

再重启服务测试,此时发现问题得以解决!!

发布了3 篇原创文章 · 获赞 0 · 访问量 5304

猜你喜欢

转载自blog.csdn.net/cjlcc/article/details/83582513