I'm trying to implement JPA in Play for Scala, following these examples documented in Java.
In the following code I get a compilation error in jpaApi.withTransaction
:
class ManageBanks @Inject() (jpaApi: JPAApi) extends Controller {
@Transactional
def readMany = {
val em = jpaApi.em
jpaApi.withTransaction( em -> { // <-- error in this line
val query = em.createQuery("from BankHib order by name")
val list = query.getResultList.asScala.toList.map(_.asInstanceOf[BankHib])
list
})
}
}
The error:
overloaded method value withTransaction with alternatives: (x$1: Runnable)Unit [T](x$1: java.util.function.Supplier[T])T [T](x$1: java.util.function.Function[javax.persistence.EntityManager,T])T cannot be applied to ((javax.persistence.EntityManager, List[admin.manage.BankHib]))
What's wrong with this code?
Lambdas in Scala use syntax
instead of
in Java.
->
in Scala is for maps.