title: org.hibernate.MappingException: Unknown entity: org.hibernate.collection.internal.PersistentBag
body: <p>My code below:</p>
  
  <pre><code>int userId = 42;
  String stringIdBook = "42";
  User user = daoUser.getUser(userId);
  List&lt;Books&gt; booksOrderedByUser = user.getBooks();
  
  for (Books x : booksOrderedByUser) {
      System.out.println(x.getTitle());
  }
  
  for (Books x : booksOrderedByUser) {
      String idBookString = Integer.toString(x.getIdBook());
      if (idBookString == stringIdBook) {
          booksOrderedByUser.remove(x.getIdBook());
          break;
      }
  
  }
  
  for (Books x : booksOrderedByUser) {
      System.out.println(x.getTitle());
  }
  
  entityManager.getTransaction().begin();
  entityManager.merge(booksOrderedByUser);
  entityManager.flush();
  entityManager.getTransaction().commit();
  
  entityManager.close();
  </code></pre>
  
  <p>When i run this jpa i got this exception:</p>
  
  <pre><code>org.hibernate.MappingException: Unknown entity: org.hibernate.collection.internal.PersistentBag
      at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:776)
      at org.hibernate.internal.SessionImpl.getEntityPersister(SessionImpl.java:1451)
      at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:147)
      at org.hibernate.event.internal.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:69)
      at org.hibernate.internal.SessionImpl.fireMerge(SessionImpl.java:839)
      at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:821)
      at org.hibernate.internal.SessionImpl.merge(SessionImpl.java:826)
      at org.hibernate.jpa.spi.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:1161)
      at servlet.returnBookServlet.doPost(returnBookServlet.java:59)
  </code></pre>
  
  <p>This code gets list of books which belong to user and delete selected. First issue is book isn't removed(I print list of books via <code>System.out.println()</code> and list is same before and after <code>booksOrderedByUser.remove(x.getIdBook()</code>). Second issue is this exception during merge. Can someone tell me what I did wrong?</p>