first before closing EM try to flush it by calling this.manager.flush()
second, where do you create your entity User? in other words, if you
create the user entity once, this is considered a already attached
entity.
I think you should create User each time you are going to persist
em.beginTransaction()
User user = new User() //this line is between begin transaction and commit
user.setId(10L);
...
em.persist(user);
em.commit();
if you're not sure whether this user is a new user or an already
persisted user then I recommend you to use user = em.merge(user);
instead, this is usually happens when you pass your entity through a
method argument.