尝试将数据输入DB时出现InvalidStateException [英] InvalidStateException while trying to enter data into DB
问题描述
我有一个方法返回特定DB的实体管理器。当我第一次使用该方法获取实体管理器时,一切正常。我可以使用实体管理器将数据保存到任何表A,B,C中。现在说我在表B中保存时出现异常
I have a method that return the entity manager for particular DB.Now when i use the method for the first time to get entity manager everything works fine.I can save data into any tables A,B,C using entity manager.Now say i get a exception while saving in table B
现在当我尝试在上面发生异常后对DB执行任何操作时,下次我尝试运行相同的代码在表A本身更新时失败。我可以看到下面的结果
Now when I try to perform any operation on DB after geting exception above, the next time i try to run same code it fails when updating in table A itself.I can see folloing eception
<openjpa-1.2.2-SNAPSHOT-r422266:778978M-OPENJPA-975 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: The factory has been closed. The stack trace at which the factory was closed is available if Runtime=TRACE logging is enabled.
at org.apache.openjpa.kernel.AbstractBrokerFactory.assertOpen(AbstractBrokerFactory.java:673)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:182)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
at ..
推荐答案
在您的代码中的某个地方,您(或框架)关闭您的的EntityManagerFactory
。确保你没有在它上面调用 close()
。
Somewhere in your code you (or a framework) close your EntityManagerFactory
. Make sure you didn't call close()
on it.
这篇关于尝试将数据输入DB时出现InvalidStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!