所以我想比较我连接的两个实体的两个ID,我想如果我给你一个代码,我会更好的解释
OfferOrder.java
@Data
@Entity
@Table(name = "offer_order", schema = "srp")
@SequenceGenerator(name = "sequence_generator", sequenceName = "srp.offer_order_seq", allocationSize = 1)
@EqualsAndHashCode(callSuper = false, exclude = { "offerOrderProjectRel", "associatedOrder" })
@ToString(callSuper = true)
@NoArgsConstructor
public class OfferOrder extends BaseEntity {
[...]
@OneToMany(mappedBy = "pk.offerOrder")
private Set<OfferOrderProjectRel> offerOrderProjectRel = new HashSet<OfferOrderProjectRel>();
[..]
}
ID位于BaseEntity
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence_generator")
protected Long id;
我必须将此ID与来自OfferOrderProjectRel的ID进行比较
@Data
@Entity
@Table(name = "offer_order_project_rel", schema = "srp")
@AssociationOverrides({
@AssociationOverride(name = "pk.offerOrder",
joinColumns = @JoinColumn(name = "offer_order_id")),
@AssociationOverride(name = "pk.project",
joinColumns = @JoinColumn(name = "project_id")) })
@EqualsAndHashCode(callSuper = false)
@ToString(callSuper = true)
@NoArgsConstructor
public class OfferOrderProjectRel {
@EmbeddedId
private OfferOrderProjectRelId pk = new OfferOrderProjectRelId();
@Transient
@NotNull
private OfferOrder offerOrder;
}
其中包含来自OfferORderProjectRelId
的嵌入式ID@Embeddable
@EqualsAndHashCode(callSuper = false)
public class OfferOrderProjectRelId implements Serializable {
@ManyToOne
private OfferOrder offerOrder;
}
所以,在我展示了重要的东西(:P)后,我要创建一个问题来休眠
private static final String SELECT_OOPR_TO_SEND = "SELECT R " +
"FROM OfferOrderProjectRel R, OfferOrder O, Project P " +
"WHERE R.project.id = P.id and O.id = R.offerOrder.id " +
"and O.type = 'ORDER' and (P.status = 'PENDING' or P.status ='PROTECTED')" ;
正如你可以看到我在那里连接另一个实体,但是一旦我通过这个,我就能做另一个我认为。
所以,当我这个hql,我得到那个错误
org.hibernate.QueryException:无法解析属性: offerOrder (或项目): pl.srp.beans.schema.srp.OfferOrderProjectRel [SELECT R FROM pl.srp.beans.schema.srp.OfferOrderProjectRel R, pl.srp.beans.schema.srp.OfferOrder O,pl.srp.beans.schema.srp.Project P WHERE R.project.id = P.id和O.id = R.offerOrder.id和O.type = 'ORDER'和(P.status ='PENDING'或P.status ='PROTECTED')]
我也试过O = R.offerOrder
等等。那么我的问题呢?
答案 0 :(得分:0)
你需要offerOrder
的公共制定者和吸气者,没有吸气剂,私人变量不能被称为