I have an entity classes in JPA as below in which maId acts as a primary key and foreign key for many other tables.
@Table(name = "Table1")
public class Test implements Serializable {
@Id
@Column(name = "maId", updatable = false, nullable = false)
private String id;
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="maId")
private MFieldData fieldData;
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="maId")
private MPS mps;
@OneToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="maId")
private MJob mJob;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name="maId")
private List<MExtension> mlExtensions;
private Date createdDate;
private Date lastUpdatedDate;
}
Now,this is my another entity.
@Table(name = "table 2")
public class Test implements Serializable {
@Id
@Column(name = "maId", updatable = false, nullable = false)
private String maId;
private Integer cmd;
private String routeId;
}
By the time I receive a request this is API. I need to Insert the data across multiple tables.
- How to implement a custom UUID (maId) generator and use it in @Id?
- I need to use the same maId which is the unique id for this request across multiple entities while inserting into the DB. I am using a dirty way to do that. But is there any JPA way to solve this problem?
Any help would be highly appreciated!