# InheritanceType.JOINED without own subtable

**URL:** <https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207>\
**Category:** Hibernate ORM\
**Created:** [March 23, 2021, 2:21am UTC](https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207 "2021-03-23T02:21:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bostandyksoft](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/bostandyksoft/32/1450_2.png) [@bostandyksoft](https://discourse.hibernate.org/u/bostandyksoft)\
**Post date:** [March 23, 2021, 2:21am UTC](https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207/1 "2021-03-23T02:21:04Z")

</div>

Hi. I needed to map 4 classes into 3 tables.

Tables:

```auto
DATA_TYPE
id number;
name varchar2;
supertype_id number;

```

```auto
OBJECT_TYPE
type_id number (foreign key to DATA_TYPE.id)
desc varchar2;

```

```auto
PROP
id number;
obj_type_id number (foreign key to OBJECT_TYPE.type_id)
name varchar2;

```

Classes:

```auto
@Entity
@Table(name = "DATA_TYPE")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "supertype_id")
public abstract class DataType {

    private Long id;
    private String name;

    @Id
    @Column(name = "ID")
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

```

```auto
@Entity
@DiscriminatorValue("2")
public class SimpleType extends DataType {
}

```

```auto
@Entity
@DiscriminatorValue("8")
@Table(name = "OBJ_TYPE")
@PrimaryKeyJoinColumn(name = "TYPE_ID")
public class ObjectType extends DataType {

    private String description;
    private List<Prop> properties;

    @Column(name = "desc", table = "OBJ_TYPE")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @OneToMany(mappedBy = "objectType", cascade = CascadeType.ALL, orphanRemoval = true)
    public List<Prop> getProperties() {
        return properties;
    }

    public void setProperties(List<Prop> properties) {
        this.properties = properties;
    }
}

```

```auto
@Entity
@Table(name = "PROP")
public class Prop {

    private Long id;
    private String name;
    private ObjectType objectType;

    @Id
    @Column(name = "ID")
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @JoinColumn(name = "OBJ_TYPE_ID",
            referencedColumnName = "TYPE_ID",
            foreignKey = @ForeignKey(
                    name = "PROP_OBJ_FK",
                    value = ConstraintMode.CONSTRAINT
            ))
    @ManyToOne(targetEntity = ObjectType.class)
    public ObjectType getObjectType() {
        return objectType;
    }

    public void setObjectType(ObjectType objectType) {
        this.objectType = objectType;
    }
}

```

But when i tried to setup this configuration, it breaks, because it could not find table for SimpleType. Is it possible to avoid it?

---

<div class="post-metadata">

**Author:** ![vapopugin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vapopugin/32/1451_2.png) [@vapopugin](https://discourse.hibernate.org/u/vapopugin)\
**Post date:** [March 23, 2021, 7:20am UTC](https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207/2 "2021-03-23T07:20:52Z")

</div>

Addition to the question:  
When we use “DataType.hbm.xml” for mapping it works fine.  
But when we use annotations for mapping it does not work.

DataType.hbm.xml:

```auto
<class name="DataType" table="DATA_TYPE" abstract="true" lazy="false" >
    <id name="id" column="ID" type="long">
        <generator class="native">
            <param name="sequence_name">SEQ</param>
        </generator>
    </id>
    <discriminator formula="SUPER_TYPE_ID"/>
    <property name="supertypeId" column="SUPER_TYPE_ID"/>
    <property name="name" column="NAME"/>
    
    <subclass name="SimpleType" discriminator-value="2"/>

    <subclass name="ObjectType" discriminator-value="8">
        <property name="description" column="desc"/>
        <set name="properties" table="PROP" inverse="true" cascade="all-delete-orphan">
            <key>
                <column name="OBJ_TYPE_ID" />
            </key>
            <one-to-many class="Prop" />
        </set>
        <join table="OBJ_TYPE">
            <key column="TYPE_ID"/>
        </join>
    </subclass>

</class>

<class name="Prop" table="PROP">
    <id name="id" column="ID" type="long">
        <generator class="native">
            <param name="sequence_name">SEQ</param>
        </generator>
    </id>
    <property name="name" column="NAME"/>
    <many-to-one name="objectType" class="ObjectType" column="OBJ_TYPE_ID" fetch="join"/>
</class>

```

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [March 23, 2021, 7:52am UTC](https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207/3 "2021-03-23T07:52:12Z")

</div>

Did you try to add `@Table(name = "DATA_TYPE")` to `SimpleType`? If that doesn’t work, please create an issue in the issue tracker([https://hibernate.atlassian.net](https://hibernate.atlassian.net)) with a test case([https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java](https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-5/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java)) that reproduces the issue.

---

<div class="post-metadata">

**Author:** ![vapopugin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vapopugin/32/1451_2.png) [@vapopugin](https://discourse.hibernate.org/u/vapopugin)\
**Post date:** [March 30, 2021, 9:44am UTC](https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207/4 "2021-03-30T09:44:31Z")

</div>

I created an issue in the issue tracker with that problem. [[HHH-14526] Problem with InheritanceType.JOINED without own subtable - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-14526)

---

<div class="post-metadata">

**Author:** ![vapopugin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vapopugin/32/1451_2.png) [@vapopugin](https://discourse.hibernate.org/u/vapopugin)\
**Post date:** [May 5, 2021, 3:06am UTC](https://discourse.hibernate.org/t/inheritancetype-joined-without-own-subtable/5207/5 "2021-05-05T03:06:29Z")

</div>

Please vote for created issue in the tracker [[HHH-14526] Problem with InheritanceType.JOINED without own subtable - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-14526)
