title: Hibernate unbound type and no explicit target entity when using generic
body: <p>I have the following two classes:</p>
  
  <pre><code>@Entity 
  @Table(name = "criteria") 
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = AbstractCriteria.TYPE, discriminatorType = DiscriminatorType.STRING)
  public abstract class AbstractCriteria&lt;T&gt; implements Serializable {
  
     public static final String TYPE = "type";
  
     ...
     @Column(name = "clazz") private Class&lt;T&gt; clazz;
     ...
  
     protected AbstractCriteria(Class&lt;T&gt; clazz) {
        this.clazz = Preconditions.checkNotNull(clazz);
     }
     ...
  
     public abstract Predicate&lt;T&gt; evaluate(T value);
  }
  
  @Entity 
  @DiscriminatorValue(CriteriaType.Values.DATETIME_IS_BETWEEN) 
  public class DateTimeIsBetweenCriteria extends AbstractCriteria&lt;DateTime&gt; {
     ...
     public DateTimeIsBetweenCriteria() {
        super(DateTime.class);
     }
     ...
  
  
     @Override 
     public Predicate&lt;DateTime&gt; evaluate(DateTime value) {
        ...
     }
  }
  </code></pre>
  
  <p>When I tried to save an instance of the DateTimeIsBetweenCriteria class, I got this exception:</p>
  
  <pre><code>Exception in thread "main" org.hibernate.AnnotationException: 
  Property ...AbstractCriteria.clazz has an unbound type and no explicit target entity.
  Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type
  </code></pre>
  
  <p>I need <code>clazz</code> for a method in <code>AbstractCriteria</code>, and <code>T</code> can be String, DateTime, Boolean, etc.</p>
  
  <p>I was thinking about making <code>clazz</code> <code>@Transient</code>, but if I do that, I still have to have another column to identify which criteria to save so that when loading the criteria back from the database, I know which kind of criteria it is. I think this is kinda hacky.</p>
  
  <p>Any ideas how I can resolve that exception without changing my design?</p>
  
  <p>I appreciate your time a lot.</p>