【发布时间】:2020-07-22 02:31:18
【问题描述】:
大家好,感谢阅读,
我有以下问题:
org.hibernate.boot.MappingException:关联 [com....core.complex.domain.Complex.outlayTypes] 引用了一个 未映射的实体 [com....core.complex.domain.Complex.outlayTypes
从昨天开始我一直在尝试解决这个问题,但我不明白问题出在哪里。另外,我不确定为什么官方休眠页面(https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#collections-set)上没有 xml 文档。
由于我是如何设计系统的,我想使用xml配置。
所以,我有 2 个实体:
复杂 (1 --- N) OutlayType
public class Complex extends AggregateRoot {
private ComplexId id;
...
private Set<OutlayType> outlayTypes;
constructors
getters and setters
public Set<OutlayType> getOutlayTypes() { return outlayTypes; }
public void setOutlayTypes(Set<OutlayType> outlayTypes) { this.outlayTypes = outlayTypes; }
}
public class OutlayType {
OutlayTypeId id;
...
constructors
getters and setters
{
所以,就像是一个单向关系,我不在乎 OutlayType 上有一个 Complex 字段。
在数据库中,我有以下内容:
CREATE TABLE `complex` (
`id` varchar(36) NOT NULL,
...
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `outlay_type` (
`id` varchar(36) NOT NULL,
...
`complex_id` varchar(36) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
这是我在 Complex.hbm.xml 文件中的 hbm.xml 配置。
<hibernate-mapping>
<class name="com....core.complex.domain.Complex" table="complex">
<composite-id name="id" class="com....core.complex.domain.valueobject.ComplexId" access="field">
<key-property column="id" name="value" length="36" access="field" />
</composite-id>
<set name="outlayTypes" cascade="all">
<key>
<column name="complex_id" not-null="true" />
</key>
<one-to-many class="com....core.complex.domain.OutlayType" />
</set>
</class>
</hibernate-mapping>
同样,like 是单向关系,我在 OutlayType.hbm.xml 上没有任何映射。
我查看了很多教程,例如:https://www.tutorialspoint.com/hibernate/hibernate_set_mapping.htm
但我不明白为什么这不起作用,并且正在抛出:
org.hibernate.boot.MappingException:关联 [com....core.complex.domain.Complex.outlayTypes] 引用了一个 未映射的实体 [com....core.complex.domain.Complex.outlayTypes
有什么想法吗?谢谢
【问题讨论】:
标签: hibernate set one-to-many hbmxml mappingexception