title: PersistentObjectException: detached entity passed to persist - Got this exception when run method 2nd time
body: <p>The first time I run the method, it works fine, the object is persisted. But the 2nd time it fails and give me the exception:</p>
  
  <pre><code>javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: br.edu.ifpb.calendario.models.Usuario
  org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1763)
  org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1677)
  org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1683)
  org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1187)
  br.edu.ifpb.calendario.dao.GenericDAO.persist(GenericDAO.java:29)
  br.edu.ifpb.calendario.servlets.CalendarioServlet.cadastrarAnotacao(CalendarioServlet.java:122)
  br.edu.ifpb.calendario.servlets.CalendarioServlet.doPost(CalendarioServlet.java:76)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  root cause
  
  org.hibernate.PersistentObjectException: detached entity passed to persist: br.edu.ifpb.calendario.models.Usuario
  org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:139)
  org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:801)
  org.hibernate.internal.SessionImpl.persist(SessionImpl.java:794)
  org.hibernate.jpa.event.internal.core.JpaPersistEventListener$1.cascade(JpaPersistEventListener.java:97)
  org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:350)
  org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:293)
  org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
  org.hibernate.engine.internal.Cascade.cascade(Cascade.java:118)
  org.hibernate.event.internal.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:442)
  org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:266)
  org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
  org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
  org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:84)
  org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
  org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
  org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
  org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
  org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
  org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
  org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
  br.edu.ifpb.calendario.dao.GenericDAO.persist(GenericDAO.java:29)
  br.edu.ifpb.calendario.servlets.CalendarioServlet.cadastrarAnotacao(CalendarioServlet.java:122)
  br.edu.ifpb.calendario.servlets.CalendarioServlet.doPost(CalendarioServlet.java:76)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>That's my method to insert a new Note to an User:</p>
  
  <pre><code>public void cadastrarAnotacao(HttpServletRequest request, HttpServletResponse response) throws ParseException, IOException {
      HttpSession session = request.getSession();
      Usuario usuario = (Usuario) session.getAttribute("usuario");
      AnotacaoDAO anotacaoDAO =  new AnotacaoDAO();
      Anotacao anotacao = new Anotacao();
  
      String mensagem = request.getParameter("mensagem");
      String dataString = request.getParameter("data");
      Date data = new SimpleDateFormat("yyyy-MM-dd").parse(dataString);
  
      anotacao.setData(data);
      anotacao.setMensagem(mensagem);
      anotacao.setUsuario(usuario);
      usuario.setAnotacao(anotacao);
      anotacaoDAO.persist(anotacao);
      anotacaoDAO.close();
  
      session.setAttribute("usuario", usuario);
      response.sendRedirect("calendario.do?op=eventos");
  }
  </code></pre>
  
  <p>It happens when try to execute the following line:</p>
  
  <pre><code>anotacaoDAO.persist(anotacao);
  </code></pre>
  
  <p>Any sugestion?
  Thanks in advance.</p>