@Entity
public class Auction{
@ManyToOne(cascade=CascadeType.MERGE)
private Member seller;
@OneToOne(cascade=CascadeType.PERSIST)
private Question question;
}
@Entity
public class Member{
}
@Entity
public class Question{
@ManyToOne(cascade=CascadeType.MERGE)
private Member personAsking;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
}
em.persist(auction);
How do I persist member if it doesn't exist, otherwise merge (update) it?
Add to your Auction.seller field CascadeType.PERSIST. Like this:
@Entity
public class Auction{
@ManyToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST})
private Member seller;
.....
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With