【问题标题】:how verify the OneToMany relationship between two entities如何验证两个实体之间的 OneToMany 关系
【发布时间】:2015-05-21 14:44:33
【问题描述】:

我在 Hibernate 中有两个具有 OneToMany 关系的实体 Parent 和 Child,Parent 有很多 Child,我想检查 Parent 是否有 Child

我使用了这些条件,但它们不起作用

if (parent.getChilds().size() == 0)

if (parent.getChilds.isEmpty())

【问题讨论】:

    标签: hibernate entity one-to-many hibernate-onetomany


    【解决方案1】:

    这些是等价的。如果您查看例如ArrayList#isEmpty() 的来源,您会发现

    public boolean isEmpty() {
        return size == 0;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 2016-09-26
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      相关资源
      最近更新 更多