Hibernate多对多映射自定义HQL不返回欲望输出

时间:2018-05-23 10:46:56

标签: hibernate spring-boot spring-data-jpa many-to-many hql

我有2个表的多对多映射。 它的罚款实际上在正常情况下,但我有一个案例,没有从一个表中显示一些基于条件标志的元素。

但我没有得到所需的输出。

这是代码。

@Entity

@Table(name =" Grocery") 公共类GroceryItemEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long grocery_id;

private String name;
private String description;

private double price;
private boolean isActive;
private Date createdDate;
private Date lastModifiedBy;

@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name = "store_id")
@JsonIgnoreProperties(value = "groceryItem", allowSetters = true)
private StoreEntity store;




@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "KeyWord_Grocery", joinColumns = @JoinColumn(name = "grocery_id"), inverseJoinColumns = @JoinColumn(name = "keyword_id"))
private Set<KeyWordEntity> keyWord;

@Entity 公共类KeyWordEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long keyword_id;

private String name;
private String description;

@ManyToMany(fetch = FetchType.LAZY,mappedBy = "keyWord",cascade =
     {CascadeType.PERSIST, CascadeType.MERGE})
private Set<GroceryItemEntity> groceryItem;

正常情况下工作正常。 但是这种方法没有返回Desire输出

//This Method will is used for search 
@Query("SELECT Ke FROM KeyWordEntity Ke  JOIN Ke.groceryItem Ge   WHERE Ke.keyword_id in :id AND Ge.isActive is true ")
public  List<KeyWordEntity> findByIds(@Param("id") List<Long> id);

这是Hibernate生成的SQL

Hibernate: select keywordent0_.keyword_id as keyword_1_2_, keywordent0_.description as descript2_2_, keywordent0_.name as name3_2_ from key_word_entity keywordent0_ inner join key_word_grocery groceryite1_ on keywordent0_.keyword_id=groceryite1_.keyword_id inner join grocery groceryite2_ on groceryite1_.grocery_id=groceryite2_.grocery_id where (keywordent0_.keyword_id in (?)) and groceryite2_.is_active=1
Hibernate: select groceryite0_.keyword_id as keyword_2_1_0_, groceryite0_.grocery_id as grocery_1_1_0_, groceryite1_.grocery_id as grocery_1_0_1_, groceryite1_.created_date as created_2_0_1_, groceryite1_.description as descript3_0_1_, groceryite1_.is_active as is_activ4_0_1_, groceryite1_.last_modified_by as last_mod5_0_1_, groceryite1_.name as name6_0_1_, groceryite1_.price as price7_0_1_, groceryite1_.store_id as store_id8_0_1_ from key_word_grocery groceryite0_ inner join grocery groceryite1_ on groceryite0_.grocery_id=groceryite1_.grocery_id where groceryite0_.keyword_id=?
Hibernate: select storeentit0_.store_id as store_id1_3_0_, storeentit0_.created_date as created_2_3_0_, storeentit0_.is247 as is3_3_0_, storeentit0_.is_active as is_activ4_3_0_, storeentit0_.last_modified_by as last_mod5_3_0_, storeentit0_.lattitude as lattitud6_3_0_, storeentit0_.longitude as longitud7_3_0_, storeentit0_.store_description as store_de8_3_0_, storeentit0_.store_name as store_na9_3_0_ from store storeentit0_ where storeentit0_.store_id=?

我希望限制数据库中isActive False(0)的Grocery Table数据,但它不起作用.ALl数据正在出现。

0 个答案:

没有答案