所以我想對兩個ID從連接我的兩個實體比較,嗯,我想更好的解釋將是,如果我表現出UA碼從實體比較ID HQL
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與我的ID從OfferOrderProjectRel
比較@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
@Embeddable
@EqualsAndHashCode(callSuper = false)
public class OfferOrderProjectRelId implements Serializable {
@ManyToOne
private OfferOrder offerOrder;
}
有embeddedID所以之後我顯示ü重要的東西(:P)的IM創造問題冬眠
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')" ;
正如你所看到的IM連接的另一個實體存在,但一旦我獲得通過這一點,我將能夠做另一個我認爲。
所以,當我勞克這個的HQL我得到errror
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 and O.id = R.offerOrder.id and O.type = 'ORDER'and(P.status ='PENDING'or P.stat us ='PROTECTED')]
我也嘗試過O = R.offerOrder
等。所以我的問題呢?
啊我忘了提及的getter和setter offerOrder等都是全自動製作 – ojciecmatki
反正我得到它,但是,使用R .pk.offerOrder。感謝您的回答;) – ojciecmatki