I have a relation between two class like this:
Smartlist -> smartlistId` is PK
AccountEmailing -> smartlistId FK,PK
AccountEmailing table might not have an initial reference record but later it could have a record
I am only using smartlist table repository
I had tried cascade.ALL
but getting null in FK table id
I have tried the following code which is working with the following combination,
initial data with
smartlist
andAccountEmailing
This is working I am getting a record in both the tables but later updating a record giving me an error as AccountEmailing already has an entry (CascadeType.PERSIST
only allows insert not update for child)
initial data with smartlist and no data in AccountEmailing
means it will not create an entry in AccountEmailing but later adding a record it creating an insert statement for AccountEmailing and from next time it always updates
I am looking for a solution that how can I update my class so I can perform CRUD on AccountEmailing:
public class Smartlist {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "smartlistId")
private Integer smartlistId;
@OneToOne( mappedBy = "smartlist", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, orphanRemoval = true)
private AccountEmailing accountEmailing;
}
@Entity
@Table(name = "account_emailing")
public class AccountEmailing implements Serializable {
@Id
@OneToOne
@JoinColumn(name = "smartlistId")
private Smartlist smartlist;
}