我目前正在尝试学习 hibernate ,它正在进行中,但我在这里遇到了一些障碍。列表。
基本上,我目前正在尝试扩展 Parent/Child example from the manual因此它使用索引列表而不是集合。
我猜测(因为手册确实没有提供很多这方面的 Material )我需要这样的东西:
<list name="benefits" table="Child">
<key column="ParentId"/>
<list-index column="position"/>
<one-to-many class="ChildClass"/>
</list>
但它不起作用
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Unable to read XML
我无法完成这项工作,我想知道正确的方法是什么?有人可以在这里给我一个提示吗?我是否将 SET 元素放置在映射文件中的 LIST 元素内?
最佳答案
你读过"Indexed collections"吗? ?如果您正在学习 Hibernate,那么您应该学习 the annotations ,而不是 XML 映射,除非有特定需要。
关于该映射,我看到的唯一奇怪的事情是您没有在一对多映射上声明“表”。它仅适用于多对多。但这并不会使映射变得不可读。我认为你的问题在其他地方。
关于java - hibernate 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7302944/