Tank you i will try.

Il 17/nov/2016 10:06, "Romain Manni-Bucau [via TomEE & OpenEJB]" <
[email protected]> ha scritto:

> 2016-11-17 9:51 GMT+01:00 mauro2java2011 <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=4680566&i=0>>:
>
> > I read from tomee jpa 101 page:
> >
> > In some cases objects or collections of objects that become Detached may
> > not have all the data you need. This can be because of lazy loading.
> With
> > lazy loading, data isn't pulled from the database and into the
> > PersistenceContext/Cache until it is requested in code. In many cases
> the
> > Collections of persistent objects returned from an
> > javax.persistence.Query.getResultList() call are completely empty until
> > you
> > iterate over them. A side effect of this is that if the Collection
> becomes
> > Detached before it's been fully read it will be permanently empty and of
> no
> > use and calling methods on the Detached Collection can cause strange
> errors
> > and exceptions to be thrown. If you wish to Detach a Collection of
> > persistent objects it is always a good idea to iterate over the
> Collection
> > at least once.
> >
> > ........
> >
> > I think it is this the problem.
> > So when i do:
> >
> > Into a stateless ejb
> >
> > em.merge (customer);
> > Collection <Orders> ordersCollection =customer.getOrdersCollection ();
> >
> > foreach (Orders ord: ordersCollection){
> > system.out.println ("Loaded Order with id=" +ord.getId ());
> > }
> > return customer;
> > // or return ordersCollection ????
> >
> > It is correct hoe iterate for avoid collection element null ???
> >
> >
> In EE nothing is correct - it is not portable. Concretely with some
> providers you can just call size() before exiting, with some other you
> need
> to call toString() on all element of the collection. That said if you do
> it
> you should really just do  jpql query with a fetch join if you can. It is
> easier and reliable IMHO.
>
>
> > Il 17/nov/2016 09:47, "Romain Manni-Bucau [via TomEE & OpenEJB]" <
> > [hidden email] <http:///user/SendEmail.jtp?type=node&node=4680566&i=1>>
> ha scritto:
> >
> > > check Movies clas in
> > > http://tomee.apache.org/examples-trunk/injection-of-
> > > entitymanager/README.html
> > >
> > >
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <https://blog-rmannibucau.rhcloud.com> | Old Blog
> > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
> > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > >
> > > 2016-11-17 9:34 GMT+01:00 mauro2java2011 <[hidden email]
> > > <http:///user/SendEmail.jtp?type=node&node=4680564&i=0>>:
> > >
> > > > Dont have a example on githup repo please ?
> > > >
> > > > Il 17/nov/2016 09:17, "Romain Manni-Bucau [via TomEE & OpenEJB]" <
> > > > [hidden email] <http:///user/SendEmail.jtp?
> > type=node&node=4680564&i=1>>
> > > ha scritto:
> > > >
> > > > > Hello Mauro
> > > > >
> > > > > Personally i try to ensure i eagerly featch these relationships
> with
> > a
> > > > > jpql
> > > > > query when possible. If really not possible using a @Stateful bean
> > > with
> > > > an
> > > > > EXTENDED persistence context can help.
> > > > >
> > > > > Le 17 nov. 2016 07:46, "mauro2java2011" <[hidden email]
> > > > > <http:///user/SendEmail.jtp?type=node&node=4680562&i=0>> a écrit
> :
> > > > >
> > > > > > i am a user of tomee 1.7.2 plus  .and 1.7.4 plus  and 7.0.2
> plus
> > .
> > > > > >
> > > > > > I have tried to generate a crud web app.
> > > > > >
> > > > > > Into my domain model i have for example a entity Customer with
> > > > > @OneToMany
> > > > > > Collection<Order> collectionOrders.
> > > > > >
> > > > > > And a Entity Order with @ManyToOne Customer customer.
> > > > > >
> > > > > > I would use the default lazy fetch type  for orderscollection
> into
> > > > > Customer
> > > > > > entity.
> > > > > >
> > > > > >
> > > > > > From a view jsf page i show the list of customer inside a table
> > > > > >
> > > > > > When i click on the row , with ajax i set the selected customer
> > into
> > > > the
> > > > > > viewScoped customerController .
> > > > > >
> > > > > >
> > > > > > So into the customerController i call a EJBFacede and i reattach
> > the
> > > > > > custoemer to em and retrive
> > > > > > the orderslist.. with :
> > > > > > inside the EJB:
> > > > > >
> > > > > >
> > > > > > public Customer reattachandLoadORdersCOllection(Customer
> > > > > > customToReattach){
> > > > > > Customer attached=em.merge(customToReattach).
> > > > > >
> > > > > > Collcetion<Orders> collection= atrtached.getOrdersCollection();
> > > > > >
> > > > > > collection.size();
> > > > > > customToReattach.setOrdersCOllection(collection):
> > > > > > return customToReattach
> > > > > > }
> > > > > >  i set the collection to  to customer  and i return it to
> > > controller.
> > > > > >
> > > > > > Into the controller i take the Customer returned from the  ejb
> with
> > > > > > ordersColletion and i set to field  Customer selected.
> > > > > >
> > > > > >
> > > > > >
> > > > > > so i you ask please :
> > > > > > On tomee or some github repo it is present a  working solution
> from
> > > a
> > > > > Tomee
> > > > > > plus  that uses OpenJPA and CDI and has AJAX elements where they
> > > need
> > > > to
> > > > > > access LAZY relationships.?
> > > > > >
> > > > > > OR that show how resolve the lazy loading
> > > > > >
> > > > > > I would understand like resolve the lazi loading with tomee
> openjpa
> > > > > >
> > > > > > tank you in advance.
> > > > > > Mauro
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > View this message in context: http://tomee-openejb.979440.
> > > > > > n4.nabble.com/tomee-example-for-resolve-the-problem-of-
> > > > > > lazy-load-tp4680561.html
> > > > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > > > >
> > > > >
> > > > >
> > > > > ------------------------------
> > > > > If you reply to this email, your message will be added to the
> > > discussion
> > > > > below:
> > > > > http://tomee-openejb.979440.n4.nabble.com/tomee-example-
> > > > > for-resolve-the-problem-of-lazy-load-tp4680561p4680562.html
> > > > > To unsubscribe from tomee example for resolve the problem of lazy
> > > load.,
> > > > click
> > > > > here
> > > > > <http://tomee-openejb.979440.n4.nabble.com/template/
> > > > NamlServlet.jtp?macro=unsubscribe_by_code&node=4680561&code=
> > > > bWF1cm8yamF2YTIwMTFAZ21haWwuY29tfDQ2ODA1NjF8LTExMTcxODc2MjU=>
> > > > > .
> > > > > NAML
> > > > > <http://tomee-openejb.979440.n4.nabble.com/template/
> > > > NamlServlet.jtp?macro=macro_viewer&id=instant_html%
> > > > 21nabble%3Aemail.naml&base=nabble.naml.namespaces.
> > > > BasicNamespace-nabble.view.web.template.NabbleNamespace-
> > > > nabble.view.web.template.NodeNamespace&breadcrumbs=
> > > > notify_subscribers%21nabble%3Aemail.naml-instant_emails%
> > > > 21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context: http://tomee-openejb.979440.
> > > > n4.nabble.com/tomee-example-for-resolve-the-problem-of-
> > > > lazy-load-tp4680561p4680563.html
> > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > >
> > >
> > >
> > > ------------------------------
> > > If you reply to this email, your message will be added to the
> discussion
> > > below:
> > > http://tomee-openejb.979440.n4.nabble.com/tomee-example-
> > > for-resolve-the-problem-of-lazy-load-tp4680561p4680564.html
> > > To unsubscribe from tomee example for resolve the problem of lazy
> load.,
> > click
> > > here
> > > <http://tomee-openejb.979440.n4.nabble.com/template/
> > NamlServlet.jtp?macro=unsubscribe_by_code&node=4680561&code=
> > bWF1cm8yamF2YTIwMTFAZ21haWwuY29tfDQ2ODA1NjF8LTExMTcxODc2MjU=>
> > > .
> > > NAML
> > > <http://tomee-openejb.979440.n4.nabble.com/template/
> > NamlServlet.jtp?macro=macro_viewer&id=instant_html%
> > 21nabble%3Aemail.naml&base=nabble.naml.namespaces.
> > BasicNamespace-nabble.view.web.template.NabbleNamespace-
> > nabble.view.web.template.NodeNamespace&breadcrumbs=
> > notify_subscribers%21nabble%3Aemail.naml-instant_emails%
> > 21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
> > >
> >
> >
> >
> >
> > --
> > View this message in context: http://tomee-openejb.979440.
> > n4.nabble.com/tomee-example-for-resolve-the-problem-of-
> > lazy-load-tp4680561p4680565.html
> > Sent from the TomEE Users mailing list archive at Nabble.com.
> >
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://tomee-openejb.979440.n4.nabble.com/tomee-example-
> for-resolve-the-problem-of-lazy-load-tp4680561p4680566.html
> To unsubscribe from tomee example for resolve the problem of lazy load., click
> here
> <http://tomee-openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4680561&code=bWF1cm8yamF2YTIwMTFAZ21haWwuY29tfDQ2ODA1NjF8LTExMTcxODc2MjU=>
> .
> NAML
> <http://tomee-openejb.979440.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: 
http://tomee-openejb.979440.n4.nabble.com/tomee-example-for-resolve-the-problem-of-lazy-load-tp4680561p4680567.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Reply via email to