You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by DonatasCiuksys <do...@mitsoft.lt> on 2015/10/23 11:19:31 UTC

TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Dear devs,

I have tried to use unsynchronized PersistenceContext with TomEE 7.0.0M1
(both OpenJPA and Hibernate 5.0.2):

@Stateful
@ConversationScoped
public class MyBean {
  @PersistenceContext(type = PersistenceContextType.EXTENDED,
synchronization = SynchronizationType.UNSYNCHRONIZED)
    private EntityManager em;

  public void doSomething() {
    em.persist(new Student());
  }

}

As PersistenceContext is unsynchronized, the code above should not write
anything to DB (unless I call em.joinTransaction()). Yet it does.

Is it a bug or not yet implemented Java EE 7 feature?

Cheers,
Donatas



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Many thanks for your report! Very appreciated!


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-10-27 10:36 GMT+01:00 DonatasCiuksys <do...@mitsoft.lt>:

> Yes, todays snapshot is working OK. Many thanks.
>
> Donatas
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676625.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by DonatasCiuksys <do...@mitsoft.lt>.
Yes, todays snapshot is working OK. Many thanks.

Donatas



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676625.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
yes, issue was auto joining of the tx for stateful entity managers. Has
been fixed as well but probably not yet propagated to the snapshot binaries.

Now this test passes:

@RunWith(ApplicationComposer.class)
@Descriptors({
    @Descriptor(name = "persistence.xml", path =
"src/main/resources/META-INF/persistence.xml")
})
@Classes(innerClassesAsBean = true, cdi = true)
public class Run {
    @Inject
    private MyBean bean;

    @Test
    public void run() {
        assertEquals(0, bean.count());
        bean.doSomething();
        assertEquals(0, bean.count());
    }

    @Stateful
    @RequestScoped
    public static class MyBean {
        @PersistenceContext(
            type = PersistenceContextType.EXTENDED,
            synchronization = SynchronizationType.UNSYNCHRONIZED)
        private EntityManager em;

        public void doSomething() {
            em.persist(new Student());
        }

        public int count() {
            return em.createQuery("select count(s) from Student s",
Number.class).getSingleResult().intValue();
        }
    }
}

Which is what you expected.



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-10-26 11:17 GMT+01:00 DonatasCiuksys <do...@mitsoft.lt>:

> Image below shows info on em.getDelegate():
>
> <http://tomee-openejb.979440.n4.nabble.com/file/n4676608/DebugInfo2.png>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676608.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by DonatasCiuksys <do...@mitsoft.lt>.
Image below shows info on em.getDelegate():

<http://tomee-openejb.979440.n4.nabble.com/file/n4676608/DebugInfo2.png> 



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676608.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by DonatasCiuksys <do...@mitsoft.lt>.
Well, entityManager instance if of class JtaEntityManager,
synchronizationType = UNSYNCHRONIZED, extended = true:

<http://tomee-openejb.979440.n4.nabble.com/file/n4676607/DebugInfo.png> 

Should I also check em.getDelegate()?



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676607.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Donatas,

did you check the entitymanager hibernate was providing you? Container only
handles createEntityManager() call and SynchronizationType is now wired.



Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-10-26 10:18 GMT+01:00 DonatasCiuksys <do...@mitsoft.lt>:

> Hi Romain,
>
> I checked with apache-tomee-7.0.0-20151026.041031-164-webprofile.zip and
> Hibernate 5.0.2, the bug is still present...
>
> Donatas
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676604.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by DonatasCiuksys <do...@mitsoft.lt>.
Hi Romain,

I checked with apache-tomee-7.0.0-20151026.041031-164-webprofile.zip and
Hibernate 5.0.2, the bug is still present...

Donatas



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676604.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by DonatasCiuksys <do...@mitsoft.lt>.
The fastest bugfix ever :) Many thanks :)

Donatas



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676570.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
done https://issues.apache.org/jira/browse/TOMEE-1644


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-10-23 12:19 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:

> I confirm it is a bug with EXTENDED usage, will fix it today probably and
> snapshot should be updated tomorrow
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <http://rmannibucau.wordpress.com> | Github
> <https://github.com/rmannibucau> | LinkedIn
> <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com>
>
> 2015-10-23 11:58 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:
>
>> In tx mode it is integrated if you want to check - will check extended
>> mode later today
>> Le 23 oct. 2015 11:44, "DonatasCiuksys" <do...@mitsoft.lt> a
>> écrit :
>>
>>> Yes, I have tried Hibernate 5.0.2, and the code above is writing to DB...
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676566.html
>>> Sent from the TomEE Dev mailing list archive at Nabble.com.
>>>
>>
>

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I confirm it is a bug with EXTENDED usage, will fix it today probably and
snapshot should be updated tomorrow


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com>

2015-10-23 11:58 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:

> In tx mode it is integrated if you want to check - will check extended
> mode later today
> Le 23 oct. 2015 11:44, "DonatasCiuksys" <do...@mitsoft.lt> a
> écrit :
>
>> Yes, I have tried Hibernate 5.0.2, and the code above is writing to DB...
>>
>>
>>
>> --
>> View this message in context:
>> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676566.html
>> Sent from the TomEE Dev mailing list archive at Nabble.com.
>>
>

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
In tx mode it is integrated if you want to check - will check extended mode
later today
Le 23 oct. 2015 11:44, "DonatasCiuksys" <do...@mitsoft.lt> a
écrit :

> Yes, I have tried Hibernate 5.0.2, and the code above is writing to DB...
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676566.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by DonatasCiuksys <do...@mitsoft.lt>.
Yes, I have tried Hibernate 5.0.2, and the code above is writing to DB...



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564p4676566.html
Sent from the TomEE Dev mailing list archive at Nabble.com.

Re: TomEE 7.0.0 does not support UNSYNCHRONIZED PersistenceContext

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

Should be supported with a jpa 2.1 implementation - ie hibernate or
eclipselink - but we may have an issue when used with extended.
Le 23 oct. 2015 11:31, "DonatasCiuksys" <do...@mitsoft.lt> a
écrit :

> Dear devs,
>
> I have tried to use unsynchronized PersistenceContext with TomEE 7.0.0M1
> (both OpenJPA and Hibernate 5.0.2):
>
> @Stateful
> @ConversationScoped
> public class MyBean {
>   @PersistenceContext(type = PersistenceContextType.EXTENDED,
> synchronization = SynchronizationType.UNSYNCHRONIZED)
>     private EntityManager em;
>
>   public void doSomething() {
>     em.persist(new Student());
>   }
>
> }
>
> As PersistenceContext is unsynchronized, the code above should not write
> anything to DB (unless I call em.joinTransaction()). Yet it does.
>
> Is it a bug or not yet implemented Java EE 7 feature?
>
> Cheers,
> Donatas
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-7-0-0-does-not-support-UNSYNCHRONIZED-PersistenceContext-tp4676564.html
> Sent from the TomEE Dev mailing list archive at Nabble.com.
>