我正在尝试使用spring数据条件查询连接用于hibernate层次结构类。有人可以帮助解决连接查询 我想在这些表之间创建连接以获取所有电话号码=?的人或zipCode =?
Ex.
`@Entity
class Person {
@ManyToOne(optional=false, fetch=FetchType.EAGER)
@JoinColumn(name="address_id", nullable=false, updatable=false)
Address address;
//setter/getter
}
@Entity
@Table(name="address")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name="address_type", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("address")
abstract class Address {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="address_id", unique=true)
private Long addressId;
@Column(name="address_type", nullable=false, insertable=false, updatable=false)
private String addressType;
}
@Entity
@Table(name="personal_address")
@DiscriminatorValue("personal")
@PrimaryKeyJoinColumn(name="address_id", referencedColumnName="address_id")
public class PersonalAddress extends Address {
@OneToOne(optional=false, fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@JoinColumn(name="phone_id", nullable=false, updatable=false)
private Phone phone;
@Column
private String zipCode;
}
public Specification<Person> build(String zipCode) {
return new Specification<Person>() {
@Override
public Predicate toPredicate(Root<Person> root,
CriteriaQuery<?> query,
CriteriaBuilder builder) {
Join<Person, Address> joinref = root.join("address");
??? How to add further join here to get the data from PersonalAddress class?????
}
`