【问题标题】:Hibernate, isAssociationType? How do I find out if an entity field is an association?休眠,是AssociationType?如何确定实体字段是否为关联?
【发布时间】:2014-08-09 12:43:53
【问题描述】:

我希望创建一个条件查询,仅当它是一个关联时才进行关联。

Date、Map、Set、int、Integer、Long 等类型太多,难以正确检查声明的字段是否为关联。

有没有一种简单的方法可以使用 Hibernate 来解决这个问题?

【问题讨论】:

    标签: java spring hibernate jakarta-ee


    【解决方案1】:

    是的,在org.hibernate.type.Type#isAssociationType()

    例如

    ClassMetadata cmd  = sessionFactory.getClassMetadata(Hibernate.getClass(entity));
    String[] propertyNames = cmd.getPropertyNames();
    for (String name : propertyNames) {
        if (cmd.getPropertyType(name).isAssociationType()) {
            // association type
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-01-24
      • 2016-12-27
      • 2021-01-15
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多