JPA return Stream OK with Kotlin 1.3 but failed with 1.4

fun findEmptyStream(batchSize: Int): Stream<RawRelation> {
    em.createQuery("select rr from RawRelation rr where rr.to is null order by rr.id asc")
      .setHint(HINT_FETCH_SIZE, batchSize) 
      .unwrap(javax.persistence.Query::class.java)
      .resultList
      .stream()
      .map { it as RawRelation }
  }

It’s a simple JPA query , returning a Stream of my class.
It is OK with Kotlin 1.3.72 , but failed with 1.4.0 . It shows :

Type mismatch.
Required:  Stream<RawRelation>
Found:  (Stream<Any!>..Stream<*>?)

I try to assign class type :
em.createQuery("..." , RawRelation::class.java)
But it doesn’t work

How to fix it ?

Thanks.

螢幕快照 2020-08-29 00.45.52

Write this instead and try again:

fun findEmptyStream(batchSize: Int): Stream<RawRelation> {
	return em.createQuery("SELECT rr FROM RawRelation rr WHERE rr.to IS NULL ORDER BY rr.id", RawRelation::class.java)
		.setHint(HINT_FETCH_SIZE, batchSize)
		.resultStream
}

wow , It works!!!
Thanks a lot ! :smile: