0
我正在使用SpringData JPARepository從MySql和MsSql數據庫中讀取數據。當我嘗試以List的形式獲取查詢結果時。它完美罰款SpringData JPARepository Stream MySql/MsSql NPE
List<Employee> findByEmployeeId(String employeeId);
但是,當我試圖讓作爲流
Stream<Employee> findByEmployeeId(String employeeId);
我得到NPE。但是這種情況是間歇性的。
java.lang.NullPointerException: null
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1044) ~[mysql-connector-java-5.1.38.jar!/:5.1.38]
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2580) ~[mysql-connector-java-5.1.38.jar!/:5.1.38]
at com.zaxxer.hikari.pool.HikariProxyResultSet.getInt(HikariProxyResultSet.java) ~[HikariCP-2.4.3.jar!/:na]
at org.hibernate.type.descriptor.sql.IntegerTypeDescriptor$2.doExtract(IntegerTypeDescriptor.java:73) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:267) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:338) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2969) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1696) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1628) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.loader.Loader.getRow(Loader.java:1515) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:726) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:696) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.loader.Loader.loadSingleRow(Loader.java:392) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.internal.ScrollableResultsImpl.prepareCurrentRow(ScrollableResultsImpl.java:237) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.hibernate.internal.ScrollableResultsImpl.next(ScrollableResultsImpl.java:121) ~[hibernate-core-4.3.11.Final.jar!/:4.3.11.Final]
at org.springframework.data.jpa.provider.PersistenceProvider$HibernateScrollableResultsIterator.hasNext(PersistenceProvider.java:396) ~[spring-data-jpa-1.9.2.RELEASE.jar!/:na]
at java.util.Iterator.forEachRemaining(Iterator.java:115) ~[na:1.8.0_66]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_66]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_66]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_66]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_66]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_66]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_66]
但是使用MongoRepository我從來沒有問題,即使有巨大的結果。
請讓我知道如果我在這裏失去了一些東西。
謝謝
你好,首先我想只有@Query。但沒有奏效。 – pvpkiran