Hibernate joining two table and fetch all records?

后端 未结 4 2098
离开以前
离开以前 2021-01-02 20:51

I have two entity class Category and Events.I need to join both the tables and fetch all records which matching the given condition

4条回答
  •  渐次进展
    2021-01-02 21:46

    Ty this below code

    public List getCategoryList(int id) throws SQLException, ClassNotFoundException, IOException {
    
    
            Session session = sessionFactory.getCurrentSession();
            return session.createCriteria(Catagory.class)
            .setFetchMode("events", FetchMode.JOIN)
            .add(Restrictions.eq("parentCatagoryId", 1))
            .list();
    
    }
    

    Hope this stuff works.

提交回复
热议问题