Assume we have a Parent
class in some library:
public abstract class Parent {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Also assume that we have a Child
class in some other library:
public class Child extends Parent {
}
I want to use Child class as embedded in one of my entities, like
@Entity
public class SomeEntity {
// id and other fields
@Embedded
private Child child;
// getters, setters etc.
}
The problem is, the fields defined in Parent
are not embedded, i.e. there are no columns for them in the corresponding table of SomeEntity
.
Just to make sure that it is because of inheritance, I first added some fields to Child
and observed that they are embedded as expected. I also tried embedding Parent directly, and the columns for them are generated this time too.
The problem is, how can I embed the fields defined in a super class?
I tried to mark child
field of SomeEntity
with @Access(AccessType.PROPERTY)
, but it did not work. I also tried to change those fields in Parent
class (i.e. name
in our example) to public but this didn't work either.
In case it is related, my project is a Spring Boot
project, with Hibernate
as the JPA
provider. Any help is appreciated.
EDIT: The attempted orm.xml
file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<embeddable class="...Child" access="PROPERTY">
<attributes>
<basic name="name">
<column nullable="false"/>
</basic>
</attributes>
</embeddable>
</entity-mappings>
I tried with access="FIELD"
and also without any access
parameter, but no luck.
To make sure that orm.xml
is loaded, I gave an invalid class
to embeddable
and observed ClassNotFoundException
, hence it is loaded.