小明博客 > 文档中心 >
SpringJPA 慎重 findAll() 切记分页
文章来源:寒梅 时间:2025-03-28
那二天,效劳器跑起去便挂,报内乱存溢出,固然那没有是第1次了。之前是原因为了统计1个数字,代码中写的是查问出去List而后统计List的Size,订正后处理题目。
那末此次从种种角度来思量题目了,然而依旧不可,开动后没有暂便报错:
java.lang.OutOfMemoryError:Javaheapspaceatjava.util.AbstractList.iterator(AbstractList.java:273)~[na:1.6.0_43]atorg.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.convertToMetaConstraints(AnnotationMetaDataProvider.java:240)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.findPropertyMetaData(AnnotationMetaDataProvider.java:222)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getPropertyMetaData(AnnotationMetaDataProvider.java:216)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.retrieveBeanConfiguration(AnnotationMetaDataProvider.java:129)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfiguration(AnnotationMetaDataProvider.java:117)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.provider.AnnotationMetaDataProvider.getBeanConfigurationForHierarchy(AnnotationMetaDataProvider.java:99)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.BeanMetaDataManager.createBeanMetaData(BeanMetaDataManager.java:160)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.metadata.BeanMetaDataManager.getBeanMetaData(BeanMetaDataManager.java:128)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:292)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.validator.internal.engine.ValidatorImpl.validate(ValidatorImpl.java:133)~[hibernate-validator-4.3.1.Final.jar:4.3.1.Final]atorg.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:136)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:102)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:228)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:115)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:287)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)~[hibernate-core-4.2.3.Final.jar:4.2.3.Final]atorg.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75)~[hibernate-entitymanager-4.2.3.Final.jar:4.2.3.Final]atorg.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:513)~[spring-orm-3.2.3.RELEASE.jar:3.2.3.RELEASE]atorg.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]atorg.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]atorg.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]atorg.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]atorg.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)~[spring-tx-3.2.3.RELEASE.jar:3.2.3.RELEASE]atorg.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)~[spring-aop-3.2.3.RELEASE.jar:3.2.3.RELEASE]由于是开动后没有暂,尔费心是内乱存走漏,随即刊出了ehcache慢存,不过没有应用慢存,还是出题目。
尔望了数据库机械的收集应用环境,创造一贯是很下,证据此次战前次的题目应当是一致的,依然洪量查问了List集中。
以后共事给二个SpringJPA查问代码纠正了1停,那二止代码,表面上前往1止数据,然则并不处置。所以添补上处置,只让他前往1止数据,而没有是靠表面上。
本去的SQL:
@Query("selectafromPhoneUserawhere(a.imei=?1anda.imsi=?2)or(a.imei2=?1anda.imsi2=?2)")能够望出,即使没有是表面上,那战之前的题目便果然一致了,老是前往洪量数据,批改后裔码:
@Query("selectafromPhoneUserawhere((a.imei=?1anda.imsi=?2)or(a.imei2=?1anda.imsi2=?2))andrownum<2")原因应用的是Oracle数据库,减少rownum属性,使数据库确实前往的是1条数据。
如许处理了题目。
是以,正在本质编程中,要注重以停几面:
(1)没有能依附表面下去限定题目的爆发。
(2)长久要分页,哪怕1册页据多些。
(3)没有要过分依附框架编程。
推举您浏览更多相关于“ spring框架分页内乱存溢出jpaJavaheapspace编程 ”的作品