我有两个左连接实体。以下是代码
Ooline.java
@Entity
@IdClass(OolineId.class)
@Table(name="OOLINE")
@NamedQuery(name="Ooline.findAll", query="SELECT o FROM Ooline o")
public class Ooline implements Serializable {
private static final long serialVersionUID = 1L;
@OneToMany(targetEntity=Oohead.class, fetch=FetchType.LAZY)
@JoinColumns({
@JoinColumn(name="OBCONO", referencedColumnName="OACONO"),
@JoinColumn(name="OBORNO", referencedColumnName="OAORNO")
})
private List<Oohead> ooheadList ;
@Id
@Column(name="OBCONO")
private BigDecimal obcono;
@Id
@Column(name="OBORNO")
private String oborno;
@Id
@Column(name="OBPONR")
private BigDecimal obponr;
@Id
@Column(name="OBPOSX")
private BigDecimal obposx;
//getter+setter
}
Oohead.java
@Entity
@IdClass(OoheadId.class)
@Table(name="OOHEAD")
@NamedQuery(name="Oohead.findAll", query="SELECT o FROM Oohead o")
public class Oohead implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne
private Ooline ooline;
@Id
@Column(name="OACONO")
private BigDecimal oacono;
@Id
@Column(name="OAORNO")
private String oaorno;
//getter+setter
}
我正在尝试执行JPQL查询
@Repository
public interface OoheadRepository extends JpaRepository<Oohead, String>
{
public static final String ORDER_HEAD_FOR_ITNO_CUNO = "SELECT o FROM Oohead o "
+ "left join o.Ooline u where u.obcono=o.oacono and u.obponr=o.oaponr and u.obcono=:cono "
+ "and u.obitno=:itno and o.oacuno=:cuno";
@Query(ORDER_HEAD_FOR_ITNO_CUNO)
public List<Oohead> getOrderHeadForItnoCuno(@Param("cono") String cono,@Param("cuno") String cuno,@Param("itno") String itno);
}
但是我得到了NullPointer异常
Caused by: java.lang.NullPointerException
at org.hibernate.cfg.annotations.CollectionBinder.bindCollectionSecondPass(CollectionBinder.java:1460) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.cfg.annotations.CollectionBinder.bindOneToManySecondPass(CollectionBinder.java:864) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:779) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:728) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
任何人都可以帮助我,这可以阻止我的工作。任何帮助将不胜感激。