PageAdvertisement extends SubjectAdvertisement SubjectAdvertisement has Advertisement Advertisement has collection of Attachment
@Where(clause = "deleted <> 'true'") @ManyToMany(fetch = FetchType.EAGER, mappedBy = "advertisements") @OrderBy("id asc") public Set<Attachment> getAttachments() { return this.attachments; }
public void setAttachments(Set<Attachment> attachments) { this.attachments = attachments; }
This query working fine in Hibernate 4.1.9 select pa from PageAdvertisement pa where pa.page = :page and pa.status = :status and pa.endDate > :now But throws exception in 4.3.4
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: Advertisement#10
The problem is Hibernate 4.3.4 generate this sql statement with this clause ( attachment2_.deleted <> 'true' ) in WHERE, while Hibernate 4.1.9 put this clause in LEFT OUTER JOIN
4.3.4 SELECT advertisem0_.advertisement_id AS advertis1_1_0_, advertisem0_.content AS content2_1_0_, advertisem0_.number_of_block AS number_o3_1_0_, advertisem0_.registered_date AS register4_1_0_, advertisem0_.status AS status5_1_0_, advertisem0_.title AS title6_1_0_, advertisem0_.type AS type7_1_0_, advertisem0_.url AS url8_1_0_, advertisem0_.user_id AS user_id9_1_0_, attachment1_.advertisement_id AS advertis2_1_1_, attachment2_.attachment_id AS attachme1_2_1_, attachment2_.attachment_id AS attachme1_6_2_, attachment2_.backup_url AS backup_u2_6_2_, attachment2_.deleted AS deleted3_6_2_, attachment2_.local_file AS local_fi4_6_2_, attachment2_.thumbnail AS thumbnai5_6_2_, attachment2_.type AS type6_6_2_, attachment2_.url AS url7_6_2_ FROM advertisement advertisem0_ LEFT OUTER JOIN advertisement_attachment attachment1_ ON advertisem0_.advertisement_id = attachment1_.advertisement_id LEFT OUTER JOIN attachment attachment2_ ON attachment1_.attachment_id = attachment2_.attachment_id WHERE ( attachment2_.deleted <> 'true' ) AND advertisem0_.advertisement_id = 10 ORDER BY attachment1_.attachment_id ASC
Hibernate 4.1.9 generate this working sql return 1 row SELECT advertisem0_.advertisement_id AS advertis1_6_1_, advertisem0_.content AS content6_1_, advertisem0_.number_of_block AS number3_6_1_, advertisem0_.registered_date AS registered4_6_1_, advertisem0_.status AS status6_1_, advertisem0_.title AS title6_1_, advertisem0_.type AS type6_1_, advertisem0_.url AS url6_1_, advertisem0_.user_id AS user9_6_1_, attachment1_.advertisement_id AS advertis2_6_3_, attachment2_.attachment_id AS attachment1_108_3_, attachment2_.attachment_id AS attachment1_18_0_, attachment2_.backup_url AS backup2_18_0_, attachment2_.deleted AS deleted18_0_, attachment2_.local_file AS local4_18_0_, attachment2_.thumbnail AS thumbnail18_0_, attachment2_.type AS type18_0_, attachment2_.url AS url18_0_ FROM advertisement advertisem0_ LEFT OUTER JOIN advertisement_attachment attachment1_ ON advertisem0_.advertisement_id = attachment1_.advertisement_id LEFT OUTER JOIN attachment attachment2_ ON attachment1_.attachment_id = attachment2_.attachment_id AND ( attachment2_.deleted <> 'true' ) WHERE advertisem0_.advertisement_id = 10 ORDER BY attachment2_.attachment_id ASC
|