You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by hwaastad <he...@waastad.org> on 2014/06/27 16:25:05 UTC

tomee eclipselink -> openjpa

Hi,
I've startet to see if I can migrate some of my projects from using
eclipselink 2.5.1 to openjpa 2.4xx.

Does anyone know if there are any resources anywhere which discribes this?.

I've just switched provider to openjpa and it seems that openjpa fetches
differently from eclipselink.

example:

1. use deltaspike repository with jta support

2. Stateless ejb handling request from cdi beans (View access scope)

3. onetomany are lazy fetched and unidirectional

in my @VASB i fecth all customers via ejb call
if I try getchildcollection for one of my parents in @VASB, it returns null.

Switching back to eclipselink, get child collection returns collection. (and
i off cource see the sql logs)

I'm quite new to openjpa, but I would expect the two would operate similar
without any changes...but obviously not.

This is tomee 1.7.0-snapshot.

My idea was actually to get openjpa works the same way my eclipselink
implementation was, and the add LRS features and more.

If this is not tomee dependent, I'll move over to stackoverflow :-)

br hw





--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: tomee eclipselink -> openjpa

Posted by Jean-Louis Monteiro <jl...@tomitribe.com>.
Well as far as I recall, XToMany relationships are lazy by default as per
the spec.
That means the object must be managed (attached, in the same transaction,
using an EPC) if you want to access the relationship content.
Otherwise, either openjpa and hibernate throws an exception which is in my
opinion fine.

I've heard Eclipselink sometimes does not behave always the same.
So basically, yes calling size when the object is still attached fires the
load of the toMany relationship but that becomes the same than changing
LAZY to EAGER in the mapping.
Another way depending on the architecture (DAO, or not, etc ...) is to use
a flag when you need to access the content of the ToMany relationship.

You can use JOIN FETCH queries as well so that you can populate with the
same query and then avoid another SQL stmt to the RDBMS.

Finally, we are working on a brand new distribution PLUME (stands for TomEE
PLus Mojorra Eclipselink).
As we support already out of the box Glassfish descriptor, the aim of this
distribution is to switch from MyFaces to Mojorra for JSF and from OpenJPA
to Eclipselink for JPA.
We hope that can help projects to migrate more easily.

Unfortunately, PLUME is not well certified and we need to fix some
remaining issues.

In anyway, I would suggest to fix the application if you can of course,
cause LAZY means you can access if the entity is still managed.
When the unit of work is finished (ie. Extended PC closed or transaction
committed) the entity is no more managed --> LazyLoadingException

Of course, this is not directly TomEE related, but JPA is fully part of the
web profile and what we provide out of the box in TomEE.
So you are welcome ;-)

Hope that helps
Jean-Louis




--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Fri, Jun 27, 2014 at 4:42 PM, pablo.a.saavedra@gmail.com <
pablo.a.saavedra@gmail.com> wrote:

> Hi,
>
> I had the same problem going from glassfish to tomee (eclipselink ->
> openjpa), collections are lazily fetched and you can't access them outside
> of the transaction. My solution was to log the size of the collection
> inside the session bean method... ugly but it worked.
>
> Regards
>
>
> On 27 June 2014 11:25, hwaastad <he...@waastad.org> wrote:
>
> > Hi,
> > I've startet to see if I can migrate some of my projects from using
> > eclipselink 2.5.1 to openjpa 2.4xx.
> >
> > Does anyone know if there are any resources anywhere which discribes
> this?.
> >
> > I've just switched provider to openjpa and it seems that openjpa fetches
> > differently from eclipselink.
> >
> > example:
> >
> > 1. use deltaspike repository with jta support
> >
> > 2. Stateless ejb handling request from cdi beans (View access scope)
> >
> > 3. onetomany are lazy fetched and unidirectional
> >
> > in my @VASB i fecth all customers via ejb call
> > if I try getchildcollection for one of my parents in @VASB, it returns
> > null.
> >
> > Switching back to eclipselink, get child collection returns collection.
> > (and
> > i off cource see the sql logs)
> >
> > I'm quite new to openjpa, but I would expect the two would operate
> similar
> > without any changes...but obviously not.
> >
> > This is tomee 1.7.0-snapshot.
> >
> > My idea was actually to get openjpa works the same way my eclipselink
> > implementation was, and the add LRS features and more.
> >
> > If this is not tomee dependent, I'll move over to stackoverflow :-)
> >
> > br hw
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212.html
> > Sent from the TomEE Users mailing list archive at Nabble.com.
> >
>

Re: tomee eclipselink -> openjpa

Posted by Romain Manni-Bucau <rm...@gmail.com>.
eclipselink simply keeps the connection ;)



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-27 18:46 GMT+02:00 hwaastad <he...@waastad.org>:

> OK,
> did test another thing.
> (I do not like the thought of just running a collection function for
> initializing a lazy colelction)
>
> a find will trigger lazy fetch.
>
> so basically what I can do is in my actionlistener before rendering dialog
> lookup the selected entity and then the lazy collection will be feched from
> db.
>
> It kind of makes me wonder how eclipselink handles this outside the
> transaction.....
>
> br hw
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670225.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: tomee eclipselink -> openjpa

Posted by hwaastad <he...@waastad.org>.
OK,
did test another thing.
(I do not like the thought of just running a collection function for
initializing a lazy colelction)

a find will trigger lazy fetch.

so basically what I can do is in my actionlistener before rendering dialog
lookup the selected entity and then the lazy collection will be feched from
db.

It kind of makes me wonder how eclipselink handles this outside the
transaction.....

br hw



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670225.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: tomee eclipselink -> openjpa

Posted by Jean-Louis Monteiro <jl...@tomitribe.com>.
yep I can recall

--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Fri, Jun 27, 2014 at 5:32 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Ok so was eclipselink surely. I recall we got it on Antonio petstore.
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-06-27 17:27 GMT+02:00 Jean-Louis Monteiro <jl...@tomitribe.com>:
>
> > Nope, with Hibernate you can also call size() on the collection (the only
> > difference between OpenJPA and Hibernate in that regard is OpenJPA
> returns
> > null and Hibernate returns LazyLoadingException).
> >
> > --
> > Jean-Louis Monteiro
> > http://twitter.com/jlouismonteiro
> > http://www.tomitribe.com
> >
> >
> > On Fri, Jun 27, 2014 at 5:22 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com
> > >
> > wrote:
> >
> > > actually that's worse. Depending the provider and the model to force
> the
> > > loading you have to:
> > > 1) do nothing (if eclipselinks has still the collection)
> > > 2) call any collection method (openjpa)
> > > 3) iterate over the full collection and call a method on all items
> (don't
> > > recall exactly if that's hibernate or a particular model with
> > eclipselink)
> > >
> > >
> > > You can also just use a stateful as backing bean which keeps track of
> the
> > > bean until @Remove method is called.
> > >
> > >
> > >
> > >
> > > Romain Manni-Bucau
> > > Twitter: @rmannibucau
> > > Blog: http://rmannibucau.wordpress.com/
> > > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> > > Github: https://github.com/rmannibucau
> > >
> > >
> > > 2014-06-27 17:17 GMT+02:00 hwaastad <he...@waastad.org>:
> > >
> > > > Hi,
> > > > thx for answering.
> > > >
> > > > the alternative would be a join fetch on queries, but it seems
> strange
> > if
> > > > this behaviour is not configurable.
> > > >
> > > > If it is, then it's easier to do migrations step by step.
> > > >
> > > > br hw
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context:
> > > >
> > >
> >
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670217.html
> > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > >
> > >
> >
>

Re: tomee eclipselink -> openjpa

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Ok so was eclipselink surely. I recall we got it on Antonio petstore.



Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-27 17:27 GMT+02:00 Jean-Louis Monteiro <jl...@tomitribe.com>:

> Nope, with Hibernate you can also call size() on the collection (the only
> difference between OpenJPA and Hibernate in that regard is OpenJPA returns
> null and Hibernate returns LazyLoadingException).
>
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
>
> On Fri, Jun 27, 2014 at 5:22 PM, Romain Manni-Bucau <rmannibucau@gmail.com
> >
> wrote:
>
> > actually that's worse. Depending the provider and the model to force the
> > loading you have to:
> > 1) do nothing (if eclipselinks has still the collection)
> > 2) call any collection method (openjpa)
> > 3) iterate over the full collection and call a method on all items (don't
> > recall exactly if that's hibernate or a particular model with
> eclipselink)
> >
> >
> > You can also just use a stateful as backing bean which keeps track of the
> > bean until @Remove method is called.
> >
> >
> >
> >
> > Romain Manni-Bucau
> > Twitter: @rmannibucau
> > Blog: http://rmannibucau.wordpress.com/
> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> > Github: https://github.com/rmannibucau
> >
> >
> > 2014-06-27 17:17 GMT+02:00 hwaastad <he...@waastad.org>:
> >
> > > Hi,
> > > thx for answering.
> > >
> > > the alternative would be a join fetch on queries, but it seems strange
> if
> > > this behaviour is not configurable.
> > >
> > > If it is, then it's easier to do migrations step by step.
> > >
> > > br hw
> > >
> > >
> > >
> > > --
> > > View this message in context:
> > >
> >
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670217.html
> > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > >
> >
>

Re: tomee eclipselink -> openjpa

Posted by Jean-Louis Monteiro <jl...@tomitribe.com>.
Nope, with Hibernate you can also call size() on the collection (the only
difference between OpenJPA and Hibernate in that regard is OpenJPA returns
null and Hibernate returns LazyLoadingException).

--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com


On Fri, Jun 27, 2014 at 5:22 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> actually that's worse. Depending the provider and the model to force the
> loading you have to:
> 1) do nothing (if eclipselinks has still the collection)
> 2) call any collection method (openjpa)
> 3) iterate over the full collection and call a method on all items (don't
> recall exactly if that's hibernate or a particular model with eclipselink)
>
>
> You can also just use a stateful as backing bean which keeps track of the
> bean until @Remove method is called.
>
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-06-27 17:17 GMT+02:00 hwaastad <he...@waastad.org>:
>
> > Hi,
> > thx for answering.
> >
> > the alternative would be a join fetch on queries, but it seems strange if
> > this behaviour is not configurable.
> >
> > If it is, then it's easier to do migrations step by step.
> >
> > br hw
> >
> >
> >
> > --
> > View this message in context:
> >
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670217.html
> > Sent from the TomEE Users mailing list archive at Nabble.com.
> >
>

Re: tomee eclipselink -> openjpa

Posted by Romain Manni-Bucau <rm...@gmail.com>.
actually that's worse. Depending the provider and the model to force the
loading you have to:
1) do nothing (if eclipselinks has still the collection)
2) call any collection method (openjpa)
3) iterate over the full collection and call a method on all items (don't
recall exactly if that's hibernate or a particular model with eclipselink)


You can also just use a stateful as backing bean which keeps track of the
bean until @Remove method is called.




Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-06-27 17:17 GMT+02:00 hwaastad <he...@waastad.org>:

> Hi,
> thx for answering.
>
> the alternative would be a join fetch on queries, but it seems strange if
> this behaviour is not configurable.
>
> If it is, then it's easier to do migrations step by step.
>
> br hw
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670217.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>

Re: tomee eclipselink -> openjpa

Posted by hwaastad <he...@waastad.org>.
Hi,
thx for answering.

the alternative would be a join fetch on queries, but it seems strange if
this behaviour is not configurable.

If it is, then it's easier to do migrations step by step.

br hw



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212p4670217.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: tomee eclipselink -> openjpa

Posted by "pablo.a.saavedra@gmail.com" <pa...@gmail.com>.
Hi,

I had the same problem going from glassfish to tomee (eclipselink ->
openjpa), collections are lazily fetched and you can't access them outside
of the transaction. My solution was to log the size of the collection
inside the session bean method... ugly but it worked.

Regards


On 27 June 2014 11:25, hwaastad <he...@waastad.org> wrote:

> Hi,
> I've startet to see if I can migrate some of my projects from using
> eclipselink 2.5.1 to openjpa 2.4xx.
>
> Does anyone know if there are any resources anywhere which discribes this?.
>
> I've just switched provider to openjpa and it seems that openjpa fetches
> differently from eclipselink.
>
> example:
>
> 1. use deltaspike repository with jta support
>
> 2. Stateless ejb handling request from cdi beans (View access scope)
>
> 3. onetomany are lazy fetched and unidirectional
>
> in my @VASB i fecth all customers via ejb call
> if I try getchildcollection for one of my parents in @VASB, it returns
> null.
>
> Switching back to eclipselink, get child collection returns collection.
> (and
> i off cource see the sql logs)
>
> I'm quite new to openjpa, but I would expect the two would operate similar
> without any changes...but obviously not.
>
> This is tomee 1.7.0-snapshot.
>
> My idea was actually to get openjpa works the same way my eclipselink
> implementation was, and the add LRS features and more.
>
> If this is not tomee dependent, I'll move over to stackoverflow :-)
>
> br hw
>
>
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/tomee-eclipselink-openjpa-tp4670212.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>