0
votes

I followed this tutorial but my doInHibernate method is ambiguity and I need a help to resolve this.

My method looks exactly:

@Test
fun createValidUser_saveUser_userSaved() {
    doInHibernate(({this.sessionFactory() }), {session: Session ->
        val expectedUser = User(
                "[email protected]",
                "testPASSWORD",
                "testFirstName",
                "testLastName")
        session.persist(expectedUser)

        val actualUser: User = session.find(User::class.java, expectedUser.id)

        assertThat(actualUser).isEqualTo(expectedUser)
    })
}

My IDE (and compiler also) says:

Overload resolution ambiguity. All these functions match.

  • public final fun doInHibernate(factorySupplier: (() → SessionFactory!)!, function: ((t: Session!) → (???..???))!): (???..???) defined in org.hibernate.testing.transaction.TransactionUtil
  • public final fun doInHibernate(factorySupplier: (() → SessionFactory!)!, function: ((t: Session!) → Unit)!): Unit defined in org.hibernate.testing.transaction.TransactionUtil
  • public final fun doInHibernate(factorySupplier: (() → SessionFactory!)!, function: ((t: Session!) → Unit)!): Unit defined in org.hibernate.testing.transaction.TransactionUtil

I'm not very familiar with anonymous classes (Java) and it's replacements in Kotlin (lambdas, SAM), probably that's where the issue lies.

It's first time I'm using doInHibernate method and it's hard to find a tutorial for that.

I'm using Springboot 2.2.4.RELEASE and Hibernate 5.4.12.Final.

1

1 Answers

1
votes

Use Unit as generic Type

doInHibernate<Unit>(({this.sessionFactory() }), {session: Session ->
        val expectedUser = User(
                "[email protected]",
                "testPASSWORD",
                "testFirstName",
                "testLastName")
        session.persist(expectedUser)

        val actualUser: User = session.find(User::class.java, expectedUser.id)

        assertThat(actualUser).isEqualTo(expectedUser)
    })