栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Hibernate : 自我加入混乱?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Hibernate : 自我加入混乱?

这些东西会解决你的问题

@Entity@Table(name = "category")public class FetchSubCategory implements Serializable {    private static final long serialVersionUID = 1L;    @Id    @GeneratedValue(strategy = GenerationType.IDENTITY)    @Column(name = "category_id")    private Integer categoryId;    @Column(name = "category_name")    private String categoryName;    @NotFound(action = NotFoundAction.IGNORE)    @ManyToOne    @JsonIgnore    @JoinColumn(name = "parent_category_id")    private FetchSubCategory mainCategory;    @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)//Avoiding empty json arrays.objects    @oneToMany(mappedBy = "mainCategory", fetch = FetchType.EAGER)    private List<FetchSubCategory> subCategory;    public Integer getCategoryId() {        return categoryId;    }    public void setCategoryId(Integer categoryId) {        this.categoryId = categoryId;    }    public String getCategoryName() {        return categoryName;    }    public void setCategoryName(String categoryName) {        this.categoryName = categoryName;    }    public FetchSubCategory getMainCategory() {        return mainCategory;    }    public void setMainCategory(FetchSubCategory mainCategory) {        this.mainCategory = mainCategory;    }    public List<FetchSubCategory> getSubCategory() {        return subCategory;    }    public void setSubCategory(List<FetchSubCategory> subCategory) {        this.subCategory = subCategory;    }

Get your sub categories

public List<FetchSubCategory> fetchSubCategory() throws SQLException, ClassNotFoundException, IOException {        List<FetchSubCategory> groupList = null;        try { Session session = sessionFactory.getCurrentSession(); Query query = session.createQuery("select distinct e FROM FetchSubCategory e INNER JOIN e.subCategory m ORDER BY m.mainCategory"); groupList = query.list();        } catch (Exception e) { e.printStackTrace();        }        return groupList;    }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/569724.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号