在我的应用程序中,我使用两个hibernate.cfg.xml文件来传递相同的mysql数据库。 hibernate cfg文件是hibernate.cfg.xml和dynamic-hibernate.cfg.xml,我在JBoss服务器中部署了我的应用程序。
有时我得到了异常,因为" org.hibernate.exception.JDBCConnectionException:在使用Dynamic-hibernate插入数据时无法获取增量生成器" 的初始值会话。但我没有在另一个Hibernate-cfg.xml会话中遇到问题。我还扩展了MYsql waittimeout。我仍然面临同样的问题
请帮我解决这个问题。
My Dynamic-hibernate-cfg.xml:
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/mydatabase</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.default_entity_mode">dynamic-map</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping file="./WEB-INF/xml/DynamicMapping.hbm.xml"/>
</session-factory>
My Another Hibernate-cfg.xml
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/mydatabase</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.isolation">2</property>
<mapping resource="HibernateMapping.hbm.xml" />
</session-factory>
我的例外是:
org.hibernate.exception.JDBCConnectionException: could not fetch initial value for increment generator
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:72)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.IncrementGenerator.getNext(IncrementGenerator.java:107)
at org.hibernate.id.IncrementGenerator.generate(IncrementGenerator.java:44)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:557)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:545)
Caused by: java.sql.SQLException: No operations allowed after connection closed.
Connection was closed due to the following exception:
** BEGIN NESTED EXCEPTION **
java.sql.SQLException
MESSAGE: Communication link failure: java.io.EOFException, underlying cause: null
** BEGIN NESTED EXCEPTION **
java.io.EOFException
STACKTRACE:
java.io.EOFException
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1394)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:1538)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1929)
答案 0 :(得分:0)
如果您完全阅读了例外情况,则说连接已经关闭。检查连接关闭的代码。并检查文件是否正确读取。