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

Vlad Mihalcea mihalcea.vlad at gmail.com
Thu Jun 16 11:25:16 EDT 2016


At first, we could add support for this method and start applying it for
new tests.
If we ever have time to migrate old tests, we should consider changing old
tests as well.

Vlad

On Thu, Jun 16, 2016 at 6:11 PM, Steve Ebersole <steve at hibernate.org> wrote:

> 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