내가 가진이최대 절전 모드 기준 1 : 1 하위 레코드가 null이 아닌 상위 레코드를 반환합니까?
같은 일대일 관계 나 부모를 반환 기준을 만들려는 부모
@JsonAutoDetect
@Entity
@Table(name = "Parent")
public class Parent{
private Integer id;
private Child child;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column (name="idparent")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
@JoinColumn(name="idchild", nullable=true)
public Child getChild() {
return child;
}
public void setChild(Child child) {
child.setParent(this);
this.child = child;
}
}
와 아이
@JsonAutoDetect
@Entity
@Table(name="Child")
public class Child{
private Integer id;
private Parent parent;
@Id
@GeneratedValue(generator = "foreign")
@GenericGenerator(name = "foreign", strategy = "foreign", parameters = { @Parameter(name = "property", value = "parent") })
@Column (name = "idchild")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@OneToOne(fetch = FetchType.LAZY, optional = true)
@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
@PrimaryKeyJoinColumn
@JsonIgnore
public Parent getParent() {
return parent;
}
public void setParent(Parent parent) {
this.parent= parent;
}
}
그 아이가있다 아니, 아니 난 tryed 솜 생각처럼
Criteria criteria = session.createCriteria(Parent.class);
criteria.add(Restrictions.isNotNull("child"));
하지만 작동하지 않습니다, 제발 좀 도와 주실 수 있습니까? 감사합니다.
호기심에서 벗어나 부모와 자녀를 사용합니다. 학부모가 자녀를 여러 명 가질 수 있습니까? 그렇다면 관계의 각 끝에서 OneToMany와 ManyToOne을 사용해야하며 API/jpql 조건에 "exists"가 있어야합니다. –