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.