I have a model called UnitDayStatistics that extends from DayStatistics with single table inheritance. I have generated metamodels UnitDayStatistics_ that inherits from DayStatistics_. In DayStatistics I have a field called day. But UnitDayStatistics_.day is null when I am trying to use it. Why?
UnitDayStatistics:
Code:
package models;
import javax.annotation.Generated;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(UnitDayStatistics.class)
public abstract class UnitDayStatistics_ extends models.DayStatistics_ {
public static volatile SingularAttribute<UnitDayStatistics, Unit> unit;
}
DayStatistics:
Code:
package models;
import javax.annotation.Generated;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
import org.joda.time.DateTime;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(DayStatistics.class)
public abstract class DayStatistics_ extends models.AbstractModel_ {
public static volatile SingularAttribute<DayStatistics, DateTime> day;
}
Usage:
Code:
public List<UnitDayStatistics> findByTimeSpanAndUnit(DateTime from, DateTime to, Unit unit) {
CriteriaQuery<UnitDayStatistics> cq = cb.createQuery(classType);
Root<UnitDayStatistics> root = cq.from(UnitDayStatistics.class);
cq.where(cb.equal(root.get(UnitDayStatistics_.unit), unit));
if(UnitDayStatistics_.day == null)
Logger.error("UnitDayStatistics_.day Null!!");
cq.where(cb.between(root.get(UnitDayStatistics_.day), from, to));
cq.orderBy(cb.desc(root.get(UnitDayStatistics_.day)));
return em.createQuery(cq).getResultList();
}