hibernate - Hibernate - hbml.xml - Unidirectional set - one-to-many
问题描述
Hello all and thanks for reading,
I have the following problem:
org.hibernate.boot.MappingException: Association [com....core.complex.domain.Complex.outlayTypes] references an unmapped entity [com....core.complex.domain.Complex.outlayTypes
I have been trying to fix this since yesterday and I dont understand what is the problem. Also, I am not sure why there are no xml documentation on the ofitial hibernate page (https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#collections-set).
Because of how I am designing the system, I want to use xml configurations.
So, I have 2 entities:
Complex (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
{
So, like is a unidirectional relation, I dont care to have a Complex field on the OutlayType.
In the DB I have the following:
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;
And this is my hbm.xml configurations in the Complex.hbm.xml file.
<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>
Again, like is a unidirectional relation, I dont have any mappings on the OutlayType.hbm.xml.
I reviewed a lot of tutorials, like: https://www.tutorialspoint.com/hibernate/hibernate_set_mapping.htm
But I dont see why this is not working, and is throwing:
org.hibernate.boot.MappingException: Association [com....core.complex.domain.Complex.outlayTypes] references an unmapped entity [com....core.complex.domain.Complex.outlayTypes
Any ideas? Thanks
解决方案
我的问题是我正在将部分核心作为库导入另一个应用程序中。并且在没有 OutlayType.hbm.xml 的情况下重新加载了 Application.yml 文件。
mapping-resources:
- infraestructure/hibernate/Complex.hbm.xml
- infraestructure/hibernate/OutlayType.hbm.xml
因此,在其中添加丢失的文件可以解决问题。谢谢阅读。
推荐阅读
- python - 如何使用 postgres\sqlalchemy 以最快的方式一次提交多条记录?
- javascript - Chart.js 过滤表时出现故障
- python - (urllib.urlretrieve 不工作)IOError: [Errno socket error] [Errno 111] Connection denied
- c++ - 对 boost asio 的未定义引用
- java - 在图像中查找矩形
- google-sheets-formula - G_sheet:找到相同的标题并将所有值带到另一个工作表(在相同的标题下)
- reactjs - OIDC 客户端 js 在 React JS 中为检查会话创建多个 iframe
- android - Android 日志中充斥着关于“资源, 入口索引(
) 超出类型 entryCount( )" - scala - 如何在 scala spark 中获取结果体的值而不是完整的结果体
- c++ - C++ 需要一些关于 Pig Latin 字符串的建议