Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>JPA annotations are not supported on interfaces. From <em>Java Persistence with Hibernate</em> (p.210): </p> <blockquote> <p>Note that the JPA specification doesn’t support any mapping annotation on an interface! This will be resolved in a future version of the specification; when you read this book, it will probably be possible with Hibernate Annotations.</p> </blockquote> <p>A possible solution would be to use an abstract Entity with a <code>TABLE_PER_CLASS</code> inheritance strategy (because you can't use a mapped superclass - which is not an entity - in associations). Something like this:</p> <pre><code>@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class AbstractAnimal { @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; ... } @Entity public class Lion extends AbstractAnimal implements Animal { ... } @Entity public class Tiger extends AbstractAnimal implements Animal { ... } @Entity public class Zoo { @Id @GeneratedValue private Long id; @OneToMany(targetEntity = AbstractAnimal.class) private Set&lt;Animal&gt; animals = new HashSet&lt;Animal&gt;(); ... } </code></pre> <p>But there is not much advantages in keeping the interface IMO (and actually, I think persistent classes should be concrete).</p> <h3>References</h3> <ul> <li><a href="https://forum.hibernate.org/viewtopic.php?f=9&amp;t=941363&amp;start=0" rel="noreferrer">Annotations, inheritance and interfaces</a></li> <li><a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;t=1003328&amp;start=0" rel="noreferrer">using MappedSuperclass in relation one to many</a></li> <li><a href="http://opensource.atlassian.com/projects/hibernate/browse/EJB-199" rel="noreferrer">Polymorphic association to a MappedSuperclass throws exception</a></li> </ul>
    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. 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