0
我有一個問題,休眠查詢,該過濾從多個實體從共同父母繼承的列。hibernate的父子查詢,不過濾兒童的FK
這裏是例子:
抽象父:
@Entity
@Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AItem
{
/** The id. */
@Id
@Column (name = "pk_id")
private Long id;
/** The date of creational. */
@Column (name = "c_date_created", nullable = true, columnDefinition = "timestamp with time zone")
private Calendar dateCreated;
/** The date of change. */
@Column (name = "c_date_changed", nullable = true, columnDefinition = "timestamp with time zone")
private Calendar dateChanged;
/** Name of item. */
@Column (name = "c_name", nullable = false)
private String name;
/** type of item. */
@Column (name = "c_type", nullable = false)
@Enumerated (EnumType.STRING)
EItemType type;
}
孩子:
@Entity
@Table (name = "t_product", schema = "am")
public class CProduct extends AItem
{
@ManyToMany (fetch = FetchType.LAZY, mappedBy = "products")
private Set<CCampaign> campaigns;
...some more attributes...
}
@Entity
@Table (name = "t_service", schema = "am")
public class CService extends AItem
{
@ManyToMany (fetch = FetchType.LAZY, mappedBy = "services")
private Set<CCampaign> campaigns;
...some more attributes...
}
ccampaign:
@Entity
@Table (name = "t_campaign", schema = "am")
public class CCampaign
{
/** The id. */
@Id
@SequenceGenerator (name = "T_CAMPAIGN_PKID_GENERATOR", sequenceName = "AM.T_CAMPAIGN_PK_ID_SEQ")
@GeneratedValue (strategy = GenerationType.AUTO, generator = "T_CAMPAIGN_PKID_GENERATOR")
@Column (name = "pk_id")
private Long id;
/**
* Products available in the campaign.
*/
@ManyToMany (fetch = FetchType.EAGER, cascade = {CascadeType.REFRESH, CascadeType.MERGE})
@JoinTable (name = "t_x_campaign_product", schema = "am", joinColumns = {@JoinColumn (name = "pk_campaign", nullable = false, updatable = false)}, inverseJoinColumns = {@JoinColumn (name = "pk_item", nullable = false, updatable = false)})
private Set<CProduct> products;
/**
* services available in the campaign.
*/
@ManyToMany (fetch = FetchType.EAGER, cascade = {CascadeType.REFRESH, CascadeType.MERGE})
@JoinTable (name = "t_x_campaign_service", schema = "am", joinColumns = {@JoinColumn (name = "pk_campaign", nullable = false, updatable = false)}, inverseJoinColumns = {@JoinColumn (name = "pk_item", nullable = false, updatable = false)})
private Set<CService> services;
}
我想所有(服務+產品)返回爲那個活動GN。
我有查詢
select distinct item from AItem item left join item.campaigns camp where camp.id = 5
什麼現在休眠所做的就是返回所有相關產品,而不是單一的服務。
有活動分配的服務。
當我運行查詢沒有指定camp.id然後查詢將返回服務。
可以幫助解決這個問題嗎?
這個問題的答案是不是我所需要的。我希望能夠在查詢中查詢這些實體。過濾器僅向HQL添加AND或OR條件。我需要修復現有的查詢。 – MarekM