简体   繁体   English

如何在休眠映射中配置列表?

[英]How to configure a List in hibernate mapping?

I'm using Hibernate mapping to config stages in my application. 我正在使用Hibernate映射在应用程序中配置阶段。 It's configured that the necessary class (here called Configurator) is injected with the stages. 已配置为将必要的类(这里称为Configurator)与阶段一起注入。

I have one list containing Object Score: 我有一个包含对象分数的列表:

private List<Score>dsScore = new ArrayList<Score>(0);

I have a database containing table Score and a list in class Student and student.hbm.xml as: 我有一个数据库,其中包含表Score和类Student和student.hbm.xml中的列表,如下所示:

 `<list name ="dsScore" table="SCORE">
                <key> 
                    <column name="SCORE_ID" not-null="true"></column>
                </key>
                <one-to-many class="model.Score"/>      
            </list>`

into a file config Student containing it, it not work. 到包含它的文件配置Student中,它不起作用。 Can anybody help me with this? 有人可以帮我吗?

  1. list hibernate type is collection with persisted ordering. list休眠类型是具有持久排序的集合。 It requires explicit mapped column in underlying table for ordering, so your mapping is missing <index>/<list-index> element. 它需要基础表中的显式映射列进行排序,因此您的映射缺少<index>/<list-index>元素。 OR you should use bag (maybe with order-by attribute) to get collection mapped to java List without persisting order. 或者,您应该使用bag (也许带有order-by属性)来将集合映射到java List而不保留顺序。 See docs 查看文件
  2. Use package attribute on <hibernate-mapping> instead of qualified class name. <hibernate-mapping>上使用package属性,而不是限定的类名。

I assume that both Student and Score classes are in model package. 我假设StudentScore类都在model包中。 The mapping then should look like 映射应该看起来像

<hibernate-mapping package="model">
    <class name="Student" table="...">
        ...
        <bag name="dsScore" table="Score" order-by="...">
            <key column="SCORE_ID" />
            <one-to-many class="Score" />
        </bag>
    </class>
</hibernate-mapping>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM