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
My problem was that I was importing part of the core as a library in another application. And the Application.yml file was reloaded without the OutlayType.hbm.xml.
So, adding the missing file in there fixed the issue. Thanks for reading.