I am using Spring Data JPA and Hibernate to create and map two tables PROCESS
and STATEMENT
, the STATEMENT
table has two FK referring to id
from the PROCESS
table and I want to have a relationship between these two tables and from Process
entity I want to have ability to find associated Statement
records when inquiry tables,
so I implemented the below entities for this purpose:
Process:
@Data
@Builder
@Entity
@Table( name = "PROCESS" )
@NoArgsConstructor
@AllArgsConstructor
public class Process {
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
private Long id;
@NotNull
@Column( name = "start_date" )
private LocalDateTime startDate;
@Column( name = "end_date" )
private LocalDateTime endDate;
@Builder.Default
@OneToMany(mappedBy = "removalProcessId", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Statement> statements = new ArrayList<>();
}
And Statement:
@Data
@Builder
@Entity
@Table( name = "STATEMENT" )
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode( callSuper = true )
public class Statement extends AuditableEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "validation_process_id", referencedColumnName = "ID" , nullable = false, foreignKey = @ForeignKey( name = "FK__VALIDATION_PROCESS_ID_TO_SECTION_REMOVAL_PROCESSES.ID" ))
private Process validationProcessId;
@Enumerated(EnumType.STRING)
@Column(name = "validation_status")
private ValidationStatus validationStatus;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "removal_process_id", referencedColumnName = "ID" , nullable = false, foreignKey = @ForeignKey( name = "FK__REMOVAL_PROCESS_ID_TO_SECTION_REMOVAL_PROCESSES.ID" ))
private Process removalProcessId;
}
Now the question is my implementation ok and standard? is there any issue or problem in my design and implementation? if Yes I would appreciate it if you guide me