本质:
package com.igorgorbunov3333.core.entities.domain;
import javax.persistence.*;
import java.util.Date;
/**
* Created by Игорь on 03.04.2016.
*/
@Entity
@Table(name = "cases")
@NamedQueries({
@NamedQuery(name = "findAllCases", query = "SELECT c FROM Case c JOIN c.client JOIN c.firstInstance " +
"JOIN c.secondInstance JOIN c.thirdInstance JOIN c.category"),
})
public class Case {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "case_number")
private String caseNumber;
@ManyToOne
@JoinColumn(name = "client_id")
private Client client;
@OneToOne
@JoinColumn(name = "first_instance_id")
private FirstInstance firstInstance;
@OneToOne
@JoinColumn(name = "second_instance_id")
private SecondInstance secondInstance;
@OneToOne
@JoinColumn(name = "third_instance_id")
private ThirdInstance thirdInstance;
@Temporal(TemporalType.DATE)
@Column(name = "closing_date")
private Date closingDate;
@ManyToOne
@JoinColumn(name = "category_id")
private Category category;
private float price;
.....
如您所见,有一个命名查询findAllCases
。我得到所有实体 ( Case
) 是这样的:
public List<Case> findAll() {
Query query = entityManager.createNamedQuery("findAllCases");
return query.getResultList();
}
但是该方法返回字段secondInstance
不为thirdInstance
null的所有实体。如何使具有空字段的实体secondInstance
被返回thirdInstance
?