Hello,
I have two annotated entities like below:
Code:
public class Item implements Serializable {
private Long id;
private String name;
private ItemBrand item_brand;
....
@ManyToOne(targetEntity=ItemBrand.class)
@NotFound(action=NotFoundAction.IGNORE)
@JoinColumn(name="item_brand")
public ItemBrand getItem_brand()...
public void setItem_brand(ItemBrand item_brand)...
}
public class ItemBrand implements Serializable {
private Long id;
private String item_brand;
....
public void setItem_brand(String item_brand)...
public String getItem_brand()...
}
And the table contents is like this:
Item
------------------------------------
id name item_brand
------------------------------------
1 Mouse 10
2 Monitor 11
ItemBrand
------------------------
id item_brand
------------------------
10 Microsoft
11 Samsung
usually, if I want to fetch all the Item data, I use this:
Code:
List list = HibernateUtil.getSessionFactory().getCurrentSession().createQuery("from Item");
it will return me:
1 Mouse Microsoft
2 Monitor Samsung
but now I want to find Item of specific ItemBrand, so if I want to get data where the ItemBrand is Samsung, for instance.
how can I do this using createQuery() ?