I have a many to many association between two tables, table A and B, and a Join table linking them:
Is there any way using JPA or DB Logic to post something in A and Join ONLY if B has certain entry??
CodePudding user response:
If A and B are Entities, you can use @PrePersist annotation. Simply @PrePersit means Before Insert, so you can check the entries in B before inserting in A.
Class A{
int id;
String name;
@PrePersist
public void beforeInsert(){
//if B has certain entry
//then save in Join
}
}
CodePudding user response:
You can just check if B has certain entries while posting A. You can check that using the JPA repository methods of B.

