操作数据时出现JPA错误

时间:2015-03-11 12:31:18

标签: java hibernate jpa jdbc connection

在我的代码中,我在检索数据时遇到以下异常。数据有几千条记录,我在数据检索和保存后也关闭了我的实体管理器。

2015-03-11 12:25:18,372 WARN    org.hibernate.util.JDBCExceptionReporter.logExceptions:233 - SQL Error: 0, SQLState: 08S01
2015-03-11 12:25:18,373 ERROR     org.hibernate.util.JDBCExceptionReporter.logExceptions:234 - Network error IOException: No buffer space available (maximum connections reached?): connect
2015-03-11 12:25:18,374 INFO  org.hibernate.event.def.DefaultLoadEventListener.onLoad:160 - Error performing load command
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1700)
at org.hibernate.loader.Loader.doQuery(Loader.java:801)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.loadEntity(Loader.java:2037)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:76)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3268)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:496)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:477)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:227)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:285)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:152)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1090)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1038)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:630)
at org.hibernate.type.EntityType.resolve(EntityType.java:438)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:139)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982)
at org.hibernate.loader.Loader.doQuery(Loader.java:857)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
at org.springframework.orm.jpa.JpaTemplate$9.doInJpa(JpaTemplate.java:315)
at org.springframework.orm.jpa.JpaTemplate$9.doInJpa(JpaTemplate.java:1)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:146)
at org.springframework.orm.jpa.JpaTemplate.find(JpaTemplate.java:306)

这是有效的,并且在中途崩溃了一半。上面显示的缓冲区空间不可用,但我不知道为什么在关闭EntityManager时也是如此。

更新 我在持久性单元定义文件中有这个

<properties>
    <property name="hibernate.show_sql" value="false" />
    <property name="hibernate.jdbc.batch_size" value="50"/>
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
    <property name="hibernate.cache.use_second_level_cache" value="false"/>

    <property name="hibernate.c3p0.timeout" value="1800"></property>
    <property name="hibernate.c3p0.idle_test_period" value="100"></property>
</properties>

0 个答案:

没有答案