我有这个1-N案例
class BaseEntity {
@Id
Long id;
String name;
}
class RelId {
@Column(name = "BU_ID", nullable = false, insertable = true, updatable = true)
private Long buId;
@Column(name = "ID", nullable = false, insertable = true, updatable = true)
private Long id;
}
class ExtA {
@EmbeddedId
private RelId id;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "ID", insertable = false, updatable = false)
private BaseEntity baseEntity;
}
class ExtB {
@EmbeddedId
private RelId id;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "ID", insertable = false, updatable = false)
private BaseEntity baseEntity;
}
class BaseEntityEx {
BaseEntity baseEntity;
ExtA extA;
ExtB extB;
}
现在我想选择Base buId
等于2
的BaseEntityEx,并带有这样的查询
@Query(value = "SELECT NEW BaseEntityEx(b, ea, eb)
+ " FROM BaseEntity b "
+ " LEFT JOIN ExtA ea ON (ea.id.id=b.id AND ea.id.buId=:buId)"
+ " LEFT JOIN ExtB eb ON (eb.id.id=b.id AND eb.id.buId=:buId)"
+ " WHERE"
+ " b.id=:id")
public BaseEntityEx getBaseEntityExByRelId(@Param("buId") long buId, @Param("id") long id);
但它不起作用。 我怎么能这样做?
P.S。我想在ExtA和ExtB上保持这种关系,因为当我 使用BaseEntity我不想懒惰地加载或不加载数百个 关系。
我获得的错误是:
antlr.SemanticException: Path expected for join!