BAEL-1159 - Simplified example (#3853)

* Squashed commit of the following:

commit b31955df9638a6217a804e61faa230d8eacb293b
Author: Juan Moreno <earth001@gmail.com>
Date:   Wed Feb 21 22:45:52 2018 -0300

    Sample code for BAEL-1159 - Working with Kotlin and JPA - earth001@gmail.com

* Squashed commit of the following:

commit 4e6e27c914a401ee6bc599c7ffe913384137646a
Author: Juan Moreno <earth001@gmail.com>
Date:   Wed Feb 21 23:26:20 2018 -0300

    Fix package names

commit b31955df9638a6217a804e61faa230d8eacb293b
Author: Juan Moreno <earth001@gmail.com>
Date:   Wed Feb 21 22:45:52 2018 -0300

    Sample code for BAEL-1159 - Working with Kotlin and JPA - earth001@gmail.com

* Added sample with null fields

* Removed unused dependency

* BAEL-1159 - Simplified example
This commit is contained in:
Juan Moreno
2018-03-19 21:28:37 -03:00
committed by Predrag Maric
parent 8cee378632
commit 86a03336f4
4 changed files with 22 additions and 15 deletions

View File

@@ -1,7 +1,5 @@
package com.baeldung.kotlin.jpa
import com.baeldung.jpa.Person
import com.baeldung.jpa.PhoneNumber
import org.hibernate.cfg.Configuration
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase
import org.hibernate.testing.transaction.TransactionUtil.doInHibernate
@@ -31,12 +29,25 @@ class HibernateKotlinIntegrationTest : BaseCoreFunctionalTestCase() {
}
@Test
fun givenPerson_whenSaved_thenFound() {
fun givenPersonWithFullData_whenSaved_thenFound() {
doInHibernate(({ this.sessionFactory() }), { session ->
val personToSave = Person(0, "John", "jhon@test.com", Arrays.asList(PhoneNumber(0, "202-555-0171"), PhoneNumber(0, "202-555-0102")))
session.persist(personToSave)
val personFound = session.find(Person::class.java, personToSave.id)
session.refresh(personFound)
assertTrue(personToSave == personFound)
})
}
@Test
fun givenPerson_whenSaved_thenFound() {
doInHibernate(({ this.sessionFactory() }), { session ->
val personToSave = Person(0, "John")
session.persist(personToSave)
val personFound = session.find(Person::class.java, personToSave.id)
session.refresh(personFound)
assertTrue(personToSave == personFound)
})
}
@@ -48,6 +59,7 @@ class HibernateKotlinIntegrationTest : BaseCoreFunctionalTestCase() {
session.persist(personToSave)
val personFound = session.find(Person::class.java, personToSave.id)
session.refresh(personFound)
assertTrue(personToSave == personFound)
})
}