Hi there,
@NaturalId only works on root entities. As with JPA 2.2 (Hibernate 5.3), caching is also supported on non root entities, this might be a good opportunity to implement the support of @NaturalId on non root entities as well.
My use case: {code:java} @Entity public class Setting extends Base<BOSetting> { private SettingType type; private String scope; private String name; private String value; private String description; public enum SettingType { APPLICATION, PROJECT, USER;
} (...) }
@Entity @Inheritance(strategy = InheritanceType.JOINED) public abstract class Base<BO extends BOBase<? extends Base<BO>>> extends DatabaseEntity<BO> implements IBase { (...) }
@MappedSuperclass public abstract class DatabaseEntity<BO extends BODatabaseEntity<? extends DatabaseEntity<BO>>> implements IDatabaseEntity, Comparable<DatabaseEntity<BO>> { (...) } {code} For compatibility reasons, we have to stick to the joined inheritance approach. As settings change rarely and are frequently queries by name, type& scope, the idea is to annotate these properies with @NaturalId. As this is currently not working, I'm effectively forced to build a separate caching mechanism. Also in perspective of implementation consistency, I think it makes sense to allow this to somehow stick to JPA 2.2, although this is a native feature.
Regards, Niko |
|