Hey everybody,

I've got started learning some Java EE stuff and choose the Glassfish server as application server for the first example. There I observe an behavior, that I do not understood completely, and hopefully here is anybody who can help.
My application is really simple, consists of content copied out from an tutorial and represents and guestbook java EE application with a jsp servlet web tier and the webbrowser as client.

The behavior is, that when I run the application the first time in the glassfish application server, everything is okay. But if I change something that requires an redeploy, I got the following error:

HTTP Status 404 - Not Found
type Status report
messageNot Found
descriptionThe requested resource is not available.
------------------------------------------------------------
GlassFish Server Open Source Edition 4.1.1

In the output I got the following warnings multiple times:
Warning: Ignoring WEB-INF/ because the containing archive D:\glassfish\glassfish4\glassfish\domains\domain1\ applications\Guestbook recorded it as a pre-existing stale file

So I played a little bit with the error and I figured out that the problem seems to be the EntityManager, which is injected into my EJB as PersistenceContext from the application server.
If i remove the EntityManager from my EJB, the problem is solved. I guess that the problem is, that I never dispose or close the EntityManager, but cause in the tutorials I saw this is never done I am not sure to do it or not.
The examples I found that dispose the EntityManager are these who provides a factory method to obtain the EntityManager manually....

Here is my EJB:

Java Code:
package guest;
 
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
 
@Stateless
public class GuestDao {
    // Injected database connection:
    @PersistenceContext private EntityManager em;
 
    // Stores a new guest:
    public void persist(Guest guest) {
        em.persist(guest);
    }
 
    // Retrieves all the guests:
    public List<Guest> getAllGuests() {
        TypedQuery<Guest> query = em.createQuery(
            "SELECT g FROM Guest g ORDER BY g.id", Guest.class);
        return query.getResultList();
    }
}
I am using the Eclipse Ide in the Mars.2 edition and Glassfish 4.1.1 as posted before.

Kind regards