映射<object1,list <integer =“”>&gt; </object1,>的Hibernate映射

时间:2012-01-23 13:14:23

标签: java sql hibernate hsqldb

所以我收到了一个新的错误,我把它缩小到了2级。我认为“分组”类的Map属性的映射必定是错误的。这是代码:

Java实体

public class Grouping {
    private long id;
    private Map<Meal, List<Integer>> mealsCounter;
}


public class Meal implements java.io.Serializable {
    private long id;
    private Grouping grouping;
}

Hibernate配置

<hibernate-mapping>

<class name="data.Grouping" table="GROUPING">
    <id name="id" type="long">
        <column name="ID" />
        <generator class="identity" />
    </id>
    <map name="mealsCounter" table="MEAL" lazy="true" access="field">
        <key>
            <column name="ID" />
        </key>
        <map-key type="data.Meal"></map-key>
        <one-to-many class="data.Meal" />
    </map>
</class>

<class name="data.Meal" table="MEAL">
    <id name="id" type="long">
        <column name="ID" />
        <generator class="assigned" />
    </id>

    <many-to-one name="grouping" class="data.Grouping" fetch="join">
        <column name="GROUPING" />
    </many-to-one>
</class>

</hibernate-mapping>

当我尝试持久化并反对时,我得到以下错误日志:

Hibernate: insert into MEAL (NAME, GROUPING, ID) values (?, ?, ?)
756 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: -177, SQLState: 23503
756 [main] ERROR org.hibernate.util.JDBCExceptionReporter - integrity constraint violation: foreign key no parent; FK240BC3E3481002 table: MEAL

0 个答案:

没有答案