I have an entity that has been previously persited and has a @OneToMany
relationship with another entity. In order to add a new entity I just add my new entity
Make sure that you are setting both sites of the relationship before persisting the changes.
child.setParent(parent);
parent.getChildren().add(child);
Parent parentWithId = em.merge(parent);
em.flush(); // make sure that the persistence context and database are in sync
parentWithId.getId(); // works
parentWithId.getChildren().get(0).getId(); // should also work