Hi,
I have a problem with a query which filters a oneToMany entity but don't take that in Select clause. I use Criteria API to do that.
I have 2 entities:
class Category { @Id @Column(name = "ID") Long id;
@Column(name = "NAME") String name;
@OneToMany (fetch = FetchType.LAZY) @JoinColumn(name = "CAT_ID") Set<SubCategory> subcats; }
class SubCategory { @Id @Column(name = "ID") Long id;
@Column(name = "CAT_ID") Long categoryId; @Column(name = "SUB_NAME") String subName; }
Generated query by Hibernate:
select this_.NAME as NAME1_1_, this_.ID as ID1_1_, subcat1_.SUB_NAME as NAME2_2_ , subcat1_.ID as NAME2_3_ from CATEGORY this_, SUB_CATEGORY subcat1_ where subcat1_.CAT_ID = this_.ID AND subcat1_.subName = 'test'
BUT I WANT: select this_.NAME as NAME1_1_, this_.ID as ID1_1_ from CATEGORY this_, SUB_CATEGORY subcat1_ where subcat1_.CAT_ID = this_.ID AND subcat1_.subName = 'test'
Any ideas?
Thanks!
|