users@glassfish.java.net

Re: WebService, persistence context and detach entity !!!

From: Sahoo <Sahoo_at_Sun.COM>
Date: Fri, 18 May 2007 15:42:49 +0530

In your case, concurrent calls to the web service will use different
persistence contexts. The entities will automatically get detached at
the end of the method invocation, as each method acts as a transaction
boundary for a SLSB. Why do you want to detach explicitly? Do you want
to explicitly control the closure that gets serialized?

Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> Hi, group
>
> I want to create a webservice that serves as a facade to query information on my system. Something like:
>
> @Stateless()
> @WebService()
> public class Facade {
>
> @PersistenceContext
> private EntityManager em;
>
> /**
> * Web service operation
> */
> @WebMethod
> public Customer getCustomer(@WebParam(name = "id") String id) {
>
> Customer c = em.find(Customer.class, id);
> System.out.println("Selected Customer: "+c);
>
> return c;
> }
>
> /**
> * Web service operation
> */
> @WebMethod
> public Channel getChannel(@WebParam(name = "id") Integer id) {
>
> Channel c = em.find(Channel.class, id);
> System.out.println("Selected Channel: "+c);
>
> return c;
> }
> }
>
> The problem is that my Customer and Channel entitys has relations and I must detach the entity berfore returning it.
>
> The question is: how can I do this safely? Is right put the statement "em.clear()" before returning? Is the use of "em.clear()" thread safe? or the "EntityManager" is the same instance and has the same persistence context for two concurrent calls?
>
> Any help will be appreciate.
> Thanks.
> [Message sent by forum member 'apapap' (apapap)]
>
> http://forums.java.net/jive/thread.jspa?messageID=217809
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>