Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JPA's concept of inheritance is based on ordinary tables. It doesn't really "get" the idea of PostgreSQL's table inheritance. That's one of the costs of working with a spec designed to expose the lowest common denominator of features and do so portably.</p> <p>See <a href="http://java.dzone.com/articles/jpa-implementation-patterns-mapping" rel="noreferrer">this guide</a> for a decent summary of JPA inheritance strategies. Note that in the <a href="http://docs.oracle.com/javaee/6/api/javax/persistence/Inheritance.html" rel="noreferrer">newer Java 6 JavaDoc for @Inheritance</a> there is a note saying that:</p> <blockquote> <p>If the Inheritance annotation is not specified or if no inheritance type is specified for an entity class hierarchy, the SINGLE_TABLE mapping strategy is used.</p> </blockquote> <p>... and if you look at how <code>SINGLE_TABLE</code> works, it's not surprising it doesn't work for you; it's expecting all subclasses to be in one big table with a magic discriminator value.</p> <p><code>InheritanceType.TABLE_PER_CLASS</code> is closer to how Pg behaves, but I suspect that the JPA impl will get a bit confused when the base type tables have entries for each entity of a leaf type. It tries to do things like <code>UNION</code> queries across the subclass tables when querying on the superclass, and that could produce odd results - at least duplication if <code>UNION</code> is used and performance issues if it uses <code>UNION ALL</code>. Depending on exactly how the provider implements the strategy it may work at least partially. You'd have to test, and the results would possibly be fairly provider specific.</p> <p>A really good implementation of PG inheritance support for JPA would probably require JPA provider extensions for a new inheritance strategy that understood the PostgreSQL extensions for inheritance and for <code>ONLY</code> queries.</p> <p>If you can convince your JPA implementation to use <code>SELECT ... FROM ONLY subclass_table</code> when in <code>InheritanceType.TABLE_PER_CLASS</code> mode then it should inter-operate OK with PostgreSQL inheritance. It would see only the non-inherited rows in each table and work with them as if they were ordinary tables. Your other non-JPA code could then keep using the inheritance features. I guess it's possible you could modify the PostgreSQL dialect code for Hibernate to do this, but personally I wouldn't go there unless I absolutely <em>had</em> to make JPA support existing PostgreSQL schema that relied heavily on inheritance.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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