JPA / JPQL:根据相关对象的集合/地图填充集合/地图? (原型样) [英] JPA/JPQL: Fill a collection/map based on related object's collection/map? (prototype-like)

查看:122
本文介绍了JPA / JPQL:根据相关对象的集合/地图填充集合/地图? (原型样)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的实体结构:

 产品1  - > N ProductCustomField 
1 1
| |
M M'
第1版 - > N'ReleaseCustomField

ProductCustomField 原型 - Release的字段列表。



我想选择一个 Release 对象所有 ReleaseCustomFields 其中 ProductCustomField 位于 Product 中,其中 Release 是。



示例:
$ b

MySoft具有自定义字段downloadURL,其默认值为。
MySoft的版本为1.0。
这个版本没有ReleaseCustomFields,但是因为它是MySoft的一个版本,所以我可以说它可能有downloadURL的自定义字段。

喜欢让MySoft 1.0发布一个包含downloadURL的地图(默认值为)。



我知道我会在SQL中做什么,它将是一个很好的复杂的SELECT,但可能。

我不知道如何在JPA / Hibernate中掌握它。



不确定如果这是在 SELECT 中尝试实现的正确方法。
也许我应该用INSERT填充 Release 的自定义字段,然后简单地依赖映射(已经可用)?

还是应该在 Release 中创建一个特殊属性,并填写特殊查询? (我不介意使用 org.hibernate。* 注释。)

或者我应该做最简单的事情 - 以 ProductCustomField 中的每个字段使用release.getProduct()。getCustomFields()并执行操作,使用 ReleaseCustomField ProductCustomField#getDefault()否则?

解决方案

<我选择了第三种方法,因为我使用Wicket框架,所以我创建了一个Model,它给出 release release.getProduct。 getCustomFields()。get(fieldName)能够获取默认值或实际值,写入时更新 releases 'field values map。



我开始获取 IllegalArgumentException:object不是声明class 的实例,但这很可能一个不同的问题。


I have such structure of entities:

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

ProductCustomField is kind of "prototype" - a list of fields which Release may have.

I'd like to select a single Release object with all ReleaseCustomFields whose ProductCustomField are in the Product of which the Release is.

Example:

MySoft has custom field "downloadURL" with default value "". MySoft has release 1.0. This release has no ReleaseCustomFields, but because it is a release of MySoft, I can tell that it may have "downloadURL" custom field.

So I would like to have MySoft 1.0 release with a map where "downloadURL" would be defined (with a default value "").

I know what would I do in SQL, it would be a nice long complex SELECT, but possible.
I don't know though how to grasp it in JPA/Hibernate.

Not sure if this is the right thing to try to achieve in SELECT. Maybe I should rather fill the Release's custom fields with an INSERT and then simply rely on mapping (which already works)?
Or should I create a special property in Release, filled with special query? (I don't mind using org.hibernate.* annotations.)
Or should I do the simplest thing - take release.getProduct().getCustomFields() and do "for each field in ProductCustomField, use what's in ReleaseCustomField, or ProductCustomField#getDefault() otherwise?

解决方案

I have chosen the third approach. Since I use the Wicket framework, I have created a Model which, given a release and release.getProduct.getCustomFields().get("fieldName") is capable of getting either default value, or the actual value, and when written to, updates releases' field values map.

I started getting IllegalArgumentException: object is not an instance of declaring class but that's most likely a different problem.

这篇关于JPA / JPQL:根据相关对象的集合/地图填充集合/地图? (原型样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆