【问题标题】:how to define <element-collection> for a List<String> field?如何为 List<String> 字段定义 <element-collection>?
【发布时间】:2012-03-21 16:38:59
【问题描述】:

如果我的对象有一个

protected List<String> fileNote;

在 orm.xml 中定义这种关系的正确方法是什么?

(注意:我确实不想使用注释。)

【问题讨论】:

  • 你指的是哪个ORM框架?
  • 对不起;我正在使用 JPA 2.0

标签: orm mapping persistence jpa-2.0


【解决方案1】:

最简单的,如果你对默认值满意的话:

<element-collection name="fileNote"/>

如果需要更多的定制,你可以走得更远:

<element-collection name="fileNote" fetch="EAGER" access="FIELD/>
  <column name="some_name_for_column_that_holds_note" />
  <collection-table name="descriptive_name_for_table">
    <join-column name="some_id" />
  </collection-table>
</element-collection/>

【讨论】:

  • 谢谢,不知道我为什么要为此苦苦挣扎。
  • 我收到此错误Caused by: org.xml.sax.SAXParseException: Element type "element-collection" must be declared. 知道吗?
猜你喜欢
  • 2019-06-20
  • 2018-08-13
  • 1970-01-01
  • 2010-10-14
  • 2010-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-02
相关资源
最近更新 更多