Redefine a property in a subclass within a SINGLE_TABLE inheritance hierarchy in Hibernate

Solution Verified - Updated -

Issue

  • Migrating from JBoss EAP 6 / Hibernate 4
  • A SINGLE_TABLE hierarchy is defined as below and a persistent String property (title/e_title) is redefined in a subclass as a JoinColumn (foreign key)

    @Entity
    @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
    @DiscriminatorColumn(name="department")
    public abstract class Employee {
        ...
        @Column(name = "e_title", updatable = false, insertable = false)
        public String getTitle() {
                return title;
        }
        ...
    }
    
    @Entity
    @DiscriminatorValue(value="writer")
    public class Writer extends Employee {
        ...
        @Column(name = "e_title") // redefine the nature of this property to serve as a foreign key
        public String getTitle() {
                return title;
        }
    ...
    }
    
    @Entity
    @DiscriminatorValue(value="editor")
    public class Editor extends Employee {
    ...
    @Column(name = "e_title") // use as an ordinary property (must also disable referential integrity in the database)
    public String getTitle() {
        return title;
    }
        ...
    }
    
  • The redefinition of the property as a foreign key appeared to work in EAP 6 / Hibernate 4, but is no longer working in EAP 7 / Hibernate 5: SQL inserts/updates of entity rows for the type where the property is treated as a String fail to include the property.

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7
  • Hibernate 5

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content