You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by ict <ic...@gmail.com> on 2016/10/07 15:09:07 UTC
Lazy loading from remote context
Hi, a simple question, how do I make a Lazy loading of a field, a course
@Entity, after having requested through a remote interface of a session bean
(OpenEjb, Tomee 1.7.4, OpenJPA):
APP_A:
@Embedd public class EmbeddCustomClass{...}
@Entity
public class Person{
..
//Default Lazy
private List<EmbeddCustomClass> surnames;
...getters and setters
}
@Remote public interface PersonEntityManagerRemote{ public Person
getPerson(int id);}
@Stateless public class PersonEntityManager implements
PersonEntityManagerRemote{
@PersistenceContext(unitName="person-pu") private EntityManager personPu;
@Override public Person getPerson(int id){return
personPu.find(Person.class, id);}
}
FROM MANAGED BEAN IN SAME APPCONTEXT LAZY WORK FINE
APP_B:
FROM REMOTE CONTEXT, BUT IN SAME RUNNING SERVER:
@Stateless public class RemoteBean{
@EJB private PersonEntityManagerRemote;
pubic void aMethod(){
Person person = PersonEntityManagerRemote.getPerson(12);//THIS WORK
FINE
List<EmbeddCustomClass> surnames = person.getSurnames();//THIS NOT LAZY
LOAD
}
}
Tank!
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Lazy-loading-from-remote-context-tp4680313.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Lazy loading from remote context
Posted by ict <ic...@gmail.com>.
Tank so much!
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Lazy-loading-from-remote-context-tp4680313p4680319.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Lazy loading from remote context
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 7 oct. 2016 20:23, "ict" <ic...@gmail.com> a écrit :
>
> ok, I understand, but there is a way to do a lazy load from a remote
context
> ???
>
Doing another remote call or request only if tou think to it.
>
>
> --
> View this message in context:
http://tomee-openejb.979440.n4.nabble.com/Lazy-loading-from-remote-context-tp4680313p4680317.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Lazy loading from remote context
Posted by ict <ic...@gmail.com>.
ok, I understand, but there is a way to do a lazy load from a remote context
???
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Lazy-loading-from-remote-context-tp4680313p4680317.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Lazy loading from remote context
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>
2016-10-07 17:34 GMT+02:00 ict <ic...@gmail.com>:
> Maybe I'm wrong, but I have already tried so unsuccessfully...
>
> Method in PersonEntityManager:
> @TransactionAttribute(TransactionAttributeType.MANDATORY)
> @Override public Person getPerson(int id){return
> personPu.find(Person.class,
> id);}
>
>
> Method in remote SessionBean:
> @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
> pubic void aMethod(){
> Person person = PersonEntityManagerRemote.getPerson(12);//THIS WORK
> FINE
>
exiting this method you change of transaction (cause of the remote thing
> List<EmbeddCustomClass> surnames = person.getSurnames();//THIS NOT
> LAZY
> LOAD
> }
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/Lazy-loading-from-remote-context-tp4680313p4680315.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Re: Lazy loading from remote context
Posted by ict <ic...@gmail.com>.
Maybe I'm wrong, but I have already tried so unsuccessfully...
Method in PersonEntityManager:
@TransactionAttribute(TransactionAttributeType.MANDATORY)
@Override public Person getPerson(int id){return personPu.find(Person.class,
id);}
Method in remote SessionBean:
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
pubic void aMethod(){
Person person = PersonEntityManagerRemote.getPerson(12);//THIS WORK
FINE
List<EmbeddCustomClass> surnames = person.getSurnames();//THIS NOT LAZY
LOAD
}
--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/Lazy-loading-from-remote-context-tp4680313p4680315.html
Sent from the TomEE Users mailing list archive at Nabble.com.
Re: Lazy loading from remote context
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi
not sure I got it all right but the constraint for lazy loading to work is
to have a single transaction so ensure the transactionality of your code is
the one you expect.
Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> | Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>
2016-10-07 17:09 GMT+02:00 ict <ic...@gmail.com>:
> Hi, a simple question, how do I make a Lazy loading of a field, a course
> @Entity, after having requested through a remote interface of a session
> bean
> (OpenEjb, Tomee 1.7.4, OpenJPA):
>
> APP_A:
> @Embedd public class EmbeddCustomClass{...}
> @Entity
> public class Person{
> ..
> //Default Lazy
> private List<EmbeddCustomClass> surnames;
> ...getters and setters
> }
> @Remote public interface PersonEntityManagerRemote{ public Person
> getPerson(int id);}
> @Stateless public class PersonEntityManager implements
> PersonEntityManagerRemote{
> @PersistenceContext(unitName="person-pu") private EntityManager
> personPu;
> @Override public Person getPerson(int id){return
> personPu.find(Person.class, id);}
> }
>
> FROM MANAGED BEAN IN SAME APPCONTEXT LAZY WORK FINE
>
> APP_B:
> FROM REMOTE CONTEXT, BUT IN SAME RUNNING SERVER:
>
> @Stateless public class RemoteBean{
>
> @EJB private PersonEntityManagerRemote;
>
> pubic void aMethod(){
> Person person = PersonEntityManagerRemote.getPerson(12);//THIS WORK
> FINE
> List<EmbeddCustomClass> surnames = person.getSurnames();//THIS NOT
> LAZY
> LOAD
> }
> }
>
> Tank!
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/Lazy-loading-from-remote-context-tp4680313.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>