Hi everyone,

I just started with GWT and Im using RequestFactory and JPA (Hibernate).

I got a View that provides a List of records and the possibility to update 
these records (create, update).
When I implemented the update - Method, I recognized that I got to get the 
entity that I want to edit, from the server.

I used the Code from the documentation 
(https://developers.google.com/web-toolkit/doc/latest/DevGuideRequestFactory):

Thats the Employee Entity Class on Server:
*//To get the Entity from Server*

  public static Employee findEmployee(Long id) {
    if (id == null) {
      return null;
    }
    EntityManager em = entityManager();
    try {
      Employee employee = em.find(Employee.class, id);
      return employee;
    } finally {
      em.close();
    }
  }

*// for updating/inserting:*

  public void persist() {
    EntityManager em = entityManager();
    try {
      em.persist(this);
    } finally {
      em.close();
    }
  }



The Docs say:

"*Any objects not returned from RequestContext.create(), such as those 
received from the server, must be enabled for changes by calling the 
RequestFactory's edit() method. Any EntityProxies returned from the getters 
of an editable proxy are also editable.*
* *

*EmployeeProxy editableEmployee = request.edit(returnedEmployee);
editableEmployee.setDepartment(newDepartment);
...
Request<Void> updateReq = request.persist().using(editableEmployee**);*"


When I tried that, everytime I tried to update my Entity, I get an exception 
that says:
"detached entity passed"


I was not able to update my entity with persist() and I had to use merge() 
instead.
I guess thats because I close() the entityManager... and all Objects received 
from this entityManager get detached.

Now I implemented the server side that way, that I just create once a 
EntityManager that stays open.
So all clients use the same Entity Manager.

Do I have to stay the EntityManager open ? If yes, where is the right place to 
close it (and when)?
I actually dont know what happens on the server side when the application is 
started.
I guess nothing happens there until the first client connects to it, right?


Regards,
Manuel


-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to