I have some tables that have some common columns and I thought that when creating entities I would have the entities extend a class where all of the mapping is defined:
@MappedSuperclass
public class AbstractLogMaster implements Serializable
{
@Id
@Basic(optional = false)
@Column("id")
protected long id;
@Column("field1")
protected String field1;
@Column("field2")
protected String field2;
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
etc...
}
@Entity
@Table(name = "logwork")
public class LogWork extends AbstractLogMaster implements Serializable
{
@Column("field3")
protected int field3;
public int getField3()
{
return field3;
}
}
Using this in a query Predicate p1 = builder.equal(logWork.get(LogWork_.field1), f1);
results in a NPE (specifically because of the logWork.get(LogWork_.field1)
part - the @StaticMetaModel doesn't seem to work with mapped superclass)
Looking at the JPA documentation I discovered that:
Mapped superclasses cannot be queried and can’t be used in EntityManager or Query operations. You must use entity subclasses of the mapped superclass in EntityManager or Query operations. Mapped superclasses can’t be targets of entity relationships. Mapped superclasses can be abstract or concrete.
Does this mean that none of the fields I map in the mapped superclass are available to be used by the extending entities in criteria queries? If so, what is the point of putting mapping into the superclass?? If not, what am I doing wrong??