I have the following defined entities:
@Entity
@Table(name = DataSourceResource.TABLE_NAME)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "DISCRIMINATOR", discriminatorType = DiscriminatorType.STRING)
@EntityListeners(EntityTimestampsTrackingListener.class)
@Access(AccessType.PROPERTY)
public abstract class DataSourceResource
extends JPAAccessibleResource
implements IDataResourceSettingsPojo, MutableSuggestedSettings, MutableCreationDate {
private static final long serialVersionUID = 6153963356796712902L;
public static final String TABLE_NAME = "DATA_SOURCE_RESOURCES";
...
}
@Entity
@Table(name = CsvDataSourceResource.TABLE_NAME)
@DiscriminatorValue("CSV")
@PrimaryKeyJoinColumn(name = IDomainObject.PROP_ID)
@Access(AccessType.PROPERTY)
public class CsvDataSourceResource extends DataSourceResource implements CSVSettings {
private static final long serialVersionUID = 5557506666263732034L;
public static final String TABLE_NAME = "CSV_SETTINGS";
...
}
@Entity
@Table(name = DataBaseSourceResource.TABLE_NAME,
indexes = {
@Index(name = "IDX_" + DataBaseSourceResource.TABLE_NAME + "_db_type", columnList = DatabaseVendorIndicator.PROP_DB_TYPE)
})
@DiscriminatorValue("DATA_BASE")
@PrimaryKeyJoinColumn(name = IDomainObject.PROP_ID)
@Access(AccessType.PROPERTY)
public class DataBaseSourceResource extends DataSourceResource implements DataBaseSettings {
private static final long serialVersionUID = 4597088449882739652L;
public static final String TABLE_NAME = "DATA_BASE_SETTINGS";
...
}
When using any Hibernate version above 5.2.12 we are experiencing a strange behavior once transaction is committed after persisting an entity - only the common fields are persisted - the "JOINED" part is not. Thus, if attempting to retrieve the persisted entity by its assigned ID we are getting null. An inspection of the actual database table confirms this is the case: the common fields exist for the persisted assigned ID, but the JOINED part is missing Here is where it is really getting interesting - there are other entities in the (same) system that used JOINED inheritance - and there it does not seem to happen. The only difference between the working ones to the failed ones is that the failed ones (i.e., the ones mentioned in this issue) also extend a @MappedSupperclass
@MappedSuperclass
@Access(AccessType.PROPERTY)
public class JPAAccessibleResource extends AccessibleResourcePojo {
private static final long serialVersionUID = 2536622015344722587L;
Other than that, I can see no other difference. As mentioned, this started happening as of 5.2.13 and up. |