Not able to get child updated with Cascade.ALL Using 6.6.2.Final

Hi together,
I don’t get it to work, that on the child table an update is done when persisting the parent entity.

Using 6.6.2.Final

This is the parent:

@Entity(name = "Organizations")
public class Organization {

    @Id
    @Column(columnDefinition = "TEXT")
    private String id;

    @Column(columnDefinition = "TEXT")
    private String orgId;

    @Column(columnDefinition = "TEXT")
    private String name;

    @Column(columnDefinition = "TEXT")
    private String street;

    @Column(columnDefinition = "TEXT")
    private String state;

    @OneToMany(cascade = CascadeType.ALL,
            mappedBy = "organization", orphanRemoval = true)
    private List<Item> items;

The item:

@Entity(name = "Items")
public class Item {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(columnDefinition = "TEXT")
    private Long id;

    @ManyToOne(fetch = FetchType.EAGER)
    private Organization organization;

    @Column(columnDefinition = "TEXT")
    private String text;

This is where I would expect an Insert statement with a subsequent update to get item and organization linked together.

		EntityManager entityManager = entityManagerFactory.createEntityManager();
		entityManager.getTransaction().begin();
		// Do stuff...

		Organization org = new Organization();
		org.setId("ID");
		org.setActive(true);
		org.setName("test");
		org.setState("DE");
		org.setOrgId("TEST_ORGID");

		Item item = new Item();
		item.setText("asdf");

		org.addItem(item);

		entityManager.persist(org);
		entityManager.getTransaction().commit();

But when this is executed only an Insert is done on both sides (Org and Item) but Item has no relationship to Org, means foreign key is null.

Am I doing something wrong?

Thanks in advance.

This collection is the inverse side, or unowned side, of a bidirectional one-to-many association. Any changes made to it will not be persisted to the database, as you’ve defined the side ruling the association using mappedBy = organization. Hibernate, and JPA for that matter, require you to always manage both sides of bidirectional associations.

Set the value of organization in your Item entity when adding it to the list and you should see the foreign key value be correctly persisted.

Hi @mbladel,
sorry for the late reply.
Thank you for the hint. I figured it out.