Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA/Hibernate SingleTable Inheritance - Sub class can not persist relations defined in the super class
    primarykey
    data
    text
    <p>I have a single table inheritance hierarchy in jpa as shown below:</p> <pre><code>@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @Table(catalog = "onedb", name = "content") @DiscriminatorColumn(name = "oid_content_type", discriminatorType = DiscriminatorType.INTEGER) public abstract class Content implements Serializable { ... @OneToMany(cascade = CascadeType.PERSIST) @JoinColumn(name = "oid_content", referencedColumnName = "oid_content") private List&lt;ContentKeyword&gt; keywords; ... @Entity public abstract class RichMedia extends Content { ... @OneToMany(mappedBy="richMedia", cascade =CascadeType.PERSIST) private Set&lt;RichMediaFile&gt; richMediaFiles; ... } @Entity @DiscriminatorValue("1") public class RichMediaImage extends RichMedia {} </code></pre> <p>As can be seen Content is the top most base class, RichMedia is the base class for RichMediaImage and Content has a list of ContentKeyword as defined as below:</p> <pre><code> @Entity @Table(catalog = "onedb", name="content_keyword") public class ContentKeyword implements Serializable { ... @ManyToOne @JoinColumn(name = "oid_content") private Content content; } </code></pre> <p>I construct a RichMediaImage and set the list of ContentKeyword on it and try to persist the whole object. The single table, content is inserted with a new row and a new id is generated but when it comes to insert into the content_keyword table this new id is not provided in the sql jpa generates:</p> <pre><code> insert into onedb.content_keyword (oid_content, keyword) values (NULL, 'test') </code></pre> <p>throwing</p> <pre><code>MySQLIntegrityConstraintViolationException: Column 'oid_content' cannot be null </code></pre> <p>I'd greatly appreciate any pointers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload