【问题标题】:JPA/JPQL: Fill a collection/map based on related object's collection/map? (prototype-like)JPA/JPQL:根据相关对象的集合/映射填充集合/映射? (原型样)
【发布时间】:2013-01-07 18:06:22
【问题描述】:

我有这样的实体结构:

Product  1 -> N   ProductCustomField
  1                       1
  |                       |
  M                       M'
Release  1 -> N'  ReleaseCustomField

ProductCustomField 是一种“原型”——Release 可能具有的字段列表。

我想选择一个Release 对象,其中所有ReleaseCustomFieldsProductCustomFieldProduct 中,而Release 在其中。

示例:

MySoft 有自定义字段“downloadURL”,默认值为“”。 MySoft 已发布 1.0。 这个版本没有ReleaseCustomFields,但是因为它是MySoft的一个版本,我可以看出它可能有“downloadURL”自定义字段。

所以我想发布 MySoft 1.0 版本,其中包含定义“downloadURL”的地图(使用默认值“”)。

我知道我会在 SQL 中做什么,这将是一个不错的长而复杂的 SELECT,但可能。
我不知道如何在 JPA/Hibernate 中掌握它。

不确定这是否是在SELECT 中尝试实现的正确目标。 也许我宁愿用 INSERT 填充 Release 的自定义字段,然后简单地依赖映射(这已经有效)?
或者我应该在Release 中创建一个特殊属性,填充特殊查询? (我不介意使用 org.hibernate.* 注释。)
或者我应该做最简单的事情 - 使用 release.getProduct().getCustomFields() 并执行“对于 ProductCustomField 中的每个字段,使用 ReleaseCustomField 中的内容,否则使用 ProductCustomField#getDefault()

【问题讨论】:

    标签: hibernate select jpa jpql prototypal-inheritance


    【解决方案1】:

    我选择了第三种方法。由于我使用 Wicket 框架,我创建了一个模型,给定 releaserelease.getProduct.getCustomFields().get("fieldName") 能够获取默认值或实际值,并在写入时更新 releases' 字段值映射。

    我开始收到IllegalArgumentException: object is not an instance of declaring class,但这很可能是另一个问题。

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 2010-09-29
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多