Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate mapping generic class with @MappedSuperClass ancestor
    text
    copied!<p>I've run into a problem and I don't know, if is possible to solve it. Let me show you my code and explain the situation. I have an abstract class <code>User</code> mapped as superclass.</p> <pre><code>@MappedSuperclass public abstract class User extends AbstractEntity { } </code></pre> <p>Then I have two classes, <code>Person</code> and <code>Company</code>, extending the superclass.</p> <pre><code>@Entity public class Person extends User { } @Entity public class Company extends User { } </code></pre> <p>Since this, everything is ok. I have two tables called by the entity names and it works june fine. But, I have some entity called <code>Invoice</code>, where I have to map <code>Person</code> or <code>Company</code> into. </p> <pre><code>@Entity public class Invoice extends AbstractEntity { @ManyToOne() @JoinColumn(name="user_id", updatable=false) private Class&lt;? extends User&gt; user; } </code></pre> <p>The problem is that I don't know, which implementation of <code>User</code> will be mapped to this <code>Invoice</code> entity. With this solution, Hibernate gives me an error <code>org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.xxx.user references an unknown entity: java.lang.Class</code> I understand it, but please, is there any way to implement this behaviour without an exception ? Or am I completely wrong and nothing similar can be done in ORM ?</p> <p><strong>I cannot use <code>private User user</code> because <code>User</code> is a <code>@MappedSuperclass</code>, not an <code>@Entity</code>.</strong></p> <p>Thanks !</p>
 

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