[hibernate-dev] Handling connections properly during testing with Java 1.8

Steve Ebersole steve at hibernate.org
Thu Jun 16 11:11:20 EDT 2016


Not sure what you are asking specifically.  You mean a task to change each
and every test in the Hibernate testsuite?


On Thu, Jun 16, 2016 at 9:18 AM Vlad Mihalcea <mihalcea.vlad at gmail.com>
wrote:

> Hi,
>
> Now that we moved to Java 1.8, would you like to add a task so that we
> manage the Session/Transaction automatically using a test utility like the
> ones I added in the documentation tests:
>
> doInHibernate( this::sessionFactory, session -> {
>    Person person = new Person();
>    person.id = 1L;
>    session.persist( person );
>
>    person.phones.add( "027-123-4567" );
>    person.phones.add( "028-234-9876" );
>    session.flush();
>
>    person.getPhones().remove( 0 );
> } );
>
> Or for JPA:
>
> doInJPA( this::entityManagerFactory, entityManager -> {
>    Person person = new Person( 1L );
>    entityManager.persist( person );
>
>
>    person.addPhone( new Phone( 1L, "landline", "028-234-9876" ) );
>    person.addPhone( new Phone( 2L, "mobile", "072-122-9876" ) );
>    entityManager.flush();
>
>    person.removePhone( person.getPhones().get( 0 ) );
> } );
>
>
> 1. The tests will be less verbose.
> 2. There are times when a test fails on MySQL and then the suite stops
> because the connection is not closed properly and the DROP command hangs.
>
> What do you think?
>
> Vlad
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>


More information about the hibernate-dev mailing list