When using Named Queries via Spring Batch's HibernateCursorItemReader, it seems AbstractProducedQuery tries to call setCacheMode on the StatelessSessionImpl, which throws an UnsupportedOperationException. Caused by: java.lang.UnsupportedOperationException at org.hibernate.internal.StatelessSessionImpl.setCacheMode(StatelessSessionImpl.java:367) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final] at org.hibernate.query.internal.AbstractProducedQuery.beforeQuery(AbstractProducedQuery.java:1325) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final] at org.hibernate.query.internal.AbstractProducedQuery.scroll(AbstractProducedQuery.java:1369) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final] at org.hibernate.query.internal.AbstractProducedQuery.scroll(AbstractProducedQuery.java:104) ~[hibernate-core-5.2.11.Final.jar:5.2.11.Final] at org.springframework.batch.item.database.HibernateItemReaderHelper.getForwardOnlyCursor(HibernateItemReaderHelper.java:126) ~[spring-batch-infrastructure-4.0.0.M3.jar:4.0.0.M3] at org.springframework.batch.item.database.HibernateCursorItemReader.doOpen(HibernateCursorItemReader.java:185) ~[spring-batch-infrastructure-4.0.0.M3.jar:4.0.0.M3] at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:146) ~[spring-batch-infrastructure-4.0.0.M3.jar:4.0.0.M3] There is a comment at the start of SharedSessionContractImplementor which suggests this may have been foreseen: // todo : this is the shared contract between Session and StatelessSession, but it defines methods that StatelessSession does not implement // (it just throws UnsupportedOperationException). To me it seems like it is better to properly isolate those methods // into just the Session hierarchy. They include (at least): // 1) get/set CacheMode Pretty confident the issue isn't in the Spring Batch calling code, but can't be sure. |