I’m trying to map JPAs with shared fields between a couple of inherited classes. For instance:
@MappedSuperclass
public abstract class BaseJPA { /* Some fields */ }
@Entity
@Table
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Party extends BaseJPA {
/* A discriminator field, and some more fields */
}
@Entity
@Table
public class Person extends Party { /* some more fields */ }
This exact setup seemed to work fine in before Hibernate 5.4, but now, all of the fields from BaseJPA are null in the Person class.
Is there something I’m missing?
I checked out your test case and it works fine for me. I added the following to verify if the listener is invoked:
Person p = entityManager.createQuery( "select p from Person p", Person.class )
.getSingleResult();
Assert.assertEquals( Long.valueOf( 3L ), p.getCreatedById() );
Yes, the Person does contain the createdById field, but only by a join.
What I would like is for both the PERSON and PARTY tables to have the created_by_party_id column.
Here’s my real schema (PostgreSQL). Please see the comments for the PARTY_TYPE_CODE and CREATED_BY_PARTY_ID columns.
CREATE TABLE PARTY (
PARTY_ID integer NOT NULL,
PARTY_TYPE_CODE integer NOT NULL, -- I'm expecting this column to only be in the base Party class, but available as a field in the Person class, because of the InheritanceType.JOINED strategy
CREATED_BY_PARTY_ID integer NOT NULL,
CONSTRAINT PARTY_pk PRIMARY KEY (PARTY_ID),
FOREIGN KEY (CREATED_BY_PARTY_ID) REFERENCES PARTY (PARTY_ID),
);
CREATE TABLE PERSON (
PARTY_ID integer NOT NULL,
FIRST_NAME varchar(40) NOT NULL,
LAST_NAME varchar(40) NOT NULL,
CREATED_BY_PARTY_ID integer NOT NULL, -- I'm expecting this column in both tables, because of @MappedSuperclass
CONSTRAINT PERSON_pk PRIMARY KEY (PARTY_ID),
CONSTRAINT PERSON_PARTY_ID_FK FOREIGN KEY (PARTY_ID) REFERENCES PARTY (PARTY_ID),
FOREIGN KEY (CREATED_BY_PARTY_ID) REFERENCES PARTY (PARTY_ID),
);
So what I would like is for the CREATED_BY_PARTY_ID to be copied (not joined) on every @Entity class in my database.
I still need the InheritanceType.JOINED for other columns (e.g. PARTY_TYPE_CODE), however.