考虑下面的实体(删除getter和setter以减少代码)-
public class Organization {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn
private List<Account> accounts;
}
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn
private List<Contact> contacts;
}
public class Contact {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn
private List<Certification> certifications;
}
public class Certification {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn
private List<Skill> skills;
}
public class Skill {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
}
我使用SpringBootJPA规范来吸引所有拥有技能认证(比如java)的组织
public static Specification<Organization> getPartner() {
return (root, cq, cb) -> {
Join<Organization, Skill> skillJoin = root.join("accounts").join("contacts")
.join("certifications").join("skills");
return cb.equal(skillJoin.get("name"), "java");
}
}
上面的代码需要8-9秒才能返回结果。可能是由于多个@onetomany连接。对性能改进有何建议:)
暂无答案!
目前还没有任何答案,快来回答吧!