Entity.merge does not cascade insert new Child record


I have been trying to solve this issue but cannot find any solution. I have a main class that contains a List of another class. Generated code using the designer below;

    //annotations here
    public class Main{

        @OneToMany(mappedBy = "main", cascade = CascadeType.ALL,fetch = FetchType.EAGER,orphanRemoval = true)
        protected List<ChildClass> childClasses;


//Child Class

 public class ChildClass{

            @ManyToOne(fetch = FetchType.EAGER, optional = false)
            @JoinColumn(name = "MAIN_ID")
            protected Main main;

The problem is that when I call entityManager.merge, it only saves record of the Main class and not the ChildClass. It works fine when I use persist though.


Please see my answer here.