I wrote two entity classes, A, B, where An and B have an one-to-many relationship, and classes An and C also have primary foreign key associations. The following
class A:
@Entity
public class A implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GenericGenerator(name = "idGenerator", strategy = "uuid")
@GeneratedValue(generator = "idGenerator")
private String id;
@Column(nullable = false)
@NotBlank
private String name;
@ManyToOne
@JoinColumn(name = "cId", referencedColumnName="id")
private C c;
}
Class B:
@Entity
public class B implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GenericGenerator(name = "idGenerator", strategy = "uuid")
@GeneratedValue(generator = "idGenerator")
private String id;
@Column(nullable = false)
@NotBlank
private String name;
@ManyToOne
@JoinColumn(name = "aId", referencedColumnName="id")
private A a;
}
BRepository.findOne(id) 6sBRepository.findFirstById(id) 100ms
ARepository.findOne(id)300msBBAACBfindOnefindBy