关于以下示例,是否可以检索AnsweredQuestion实例列表作为Question的对象?
@MappedSuperclass
public abstract class Question{
@Column(name="TITLE")
private String title;
...
}
@Entity
@Table(name="ANSWEREDQUESTION")
public class AnsweredQuestion extends Question
{
@Column(name="ANSWER")
private String answer;
...
}
因为后代类有很多,所以只检索几列对我来说非常重要。我尝试了如下操作,但它仍然返回AnsweredQuestion列表:
queryStr = " select q from AnsweredQuestion q where ..."
TypedQuery<Question> query = entityManager.createQuery(queryStr, Question.class);
return query.setParameter( ... ).getResultList();