我有这个实体:
@Entity
@Table(name = "entry")
@SqlResultSetMapping(
name = "viewEntry",
entities =
@EntityResult(entityClass = ViewEntry.class,
fields = {
@FieldResult(name="id", column = "id"),
@FieldResult(name="guid", column = "guid"),
@FieldResult(name="link", column = "link"),
@FieldResult(name="descr", column = "descr"),
@FieldResult(name="pubDate", column = "pub_date"),
@FieldResult(name="read", column = "my_read")
}
)
)
public class ViewEntry implements Serializable {
@Id
private Integer id;
private String guid;
private String link;
private String descr;
private Date pubDate;
@Transient
private Boolean read;
}
该字段read
位于另一个表中,因此我将其设置为瞬态,以防止 JPA 映射错误。要检索实体的内容,我想使用如下所示的本机查询:
select id,guid,link,descr,pub_date,feed_id,user_id,is_read as my_read from entry join user_to_entry ....
-- skipped dynamic part of query
问题是我不知道如何将本机查询映射到我的实体。特别是我不知道 EntityManager 是否会忽略 @Transient 字段。请帮忙。