users@glassfish.java.net

WebService, persistence context and detach entity !!!

From: <glassfish_at_javadesktop.org>
Date: Fri, 18 May 2007 02:48:48 PDT

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