JPA Container not synchronized with database

I am having an issue with my JPA Containers that I haven’t been able to figure out. Here is an example:

Lets say I have 2 objects - Parent and Child such that the each parent has a reference to a child and vice versa.

I have one JPAContainer for each of these Entity classes so I can easily display them an all their data in a Table. When I go to edit one of the entries in the Parent table (using techniques similar to those in the jpacontainer-addressbook-demo), it updates the reference in the Parent table, but the Child that refers to the parent remains unchanged.

Before


Parent Table


Name | Child

John Tom


Child Table

Name | Parent
Tom | John

After


Parent Table

Name | Child
Jim Tom


Child Table

Name | Parent
Tom | John

So the first table contains the correct data but the second doesn’t

Any thoughts on how to efficiently fix this? I did something with the CascadeType.ALL for the @OneToOne relationship and refreshed both JPAContainers and that has been the only thing that’s worked so far, but I know it’s inneffienct to refresh the entire container. Is there a better way?

Thanks,
-Ryan

Here is a more concrete example with code:

@Entity
public class Child {   
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
 
    private String name;
    
    @OneToOne
    private Parent parent;

    //getters + setters
}
@Entity
public class Parent {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    
    private String name;
    
    @OneToOne(mappedBy="parent")
    private Child child;

    //getters + setters
}

public class MainView extends Panel {
    
    Table parentTable;
    Table childTable;
    JPAContainer<Parent> parentData;
    JPAContainer<Child> childData;
    
    Button edit, save;
    
    public MainView() {
        parentData = JPAContainerFactory.make(Parent.class, JpaAddressbookUI.PERSISTENCE_UNIT);
        childData = JPAContainerFactory.make(Child.class, JpaAddressbookUI.PERSISTENCE_UNIT);
        
//        Parent p1 = new Parent();
//        Child c1 = new Child();
//        p1.setName("John");
//        c1.setName("Tom");
//        p1.setChild(c1);
//        c1.setParent(p1);
//        parentData.addEntity(p1);
        
        parentData.addNestedContainerProperty("child.name");
        childData.addNestedContainerProperty("parent.name");
        //childData.addEntity(c1);
        
        parentTable = new Table("Parent Table", parentData);
        parentTable.setVisibleColumns("name", "child.name");
        childTable = new Table("Child Table", childData);
        childTable.setVisibleColumns("name", "parent.name");
        
        edit = new Button("Edit");
        edit.addClickListener(new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                parentTable.setEditable(true);
                childTable.setEditable(true);
            }
        });
        save = new Button("Save");
        save.addClickListener(new ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                parentTable.commit();
                childTable.commit();
                parentTable.setEditable(false);
                childTable.setEditable(false);
            }
        });
        
        Layout layout = new VerticalLayout();
        layout.addComponent(new HorizontalLayout(parentTable, childTable));
        layout.addComponent(new HorizontalLayout(edit, save));
        
        setContent(layout);
    }

}

So when I edit and save the table, the reference in the other table does not update in real time. However, the other reference does update if the web page is refreshed or if the application is restarted (with the ddl-generation=“none” in the persistence.xml file).

Any thoughts?