I have two entities, with the following JPA annotations:
@Entity @Table(name = "Owner") public class Owner implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private long id; @OneToOne(fetch=FetchType.EAGER , cascade=CascadeType.ALL) @JoinColumn(name="Data_id") private Data Data; } @Entity @Table(name = "Data") public class Data implements Serializable { @Id private long id; }
The owner and the data have a one-to-one mapping, and the owner is the owner. The problem occurs when I execute: owner.setData (null); ownerDao.update (owner) ; The Owner Data_id table becomes null, that's right.
But the line "Data" is not deleted automatically. I have to write another DataDao and one more service level for transferring two actions (ownerDao.update (owner); dataDao.delete (data);)
Is it possible to make a data row automatically deleted if the owner has set the owner to zero?
orm hibernate jpa one-to-one
smallufo
source share