我有一个带有实体@Transient 字段的实体,当我运行查询时出现错误。
查询与实体瞬时字段有连接
@Entity
@Table(name = "OTHER")
public class OtherEntity implements Serializable {
@Id
private Long id
@Column( name = "code" )
private String code;
}
@Entity
@Table(name = "MARKER")
public class MarkerEntity implements Serializable {
@Id
private Long id
@Column(name = "OTHER_FIELD")
private Long otherId;
@Transient
private OtherEntity other;
public MarkerEntity(Long otherId, OtherEntity other) {
this.otherId = otherId;
this.other = other;
}
}
这是 jpa 查询
@Query("SELECT " +
"new MarkerEntity(" +
" o.id, " +
" new OtherEntity(o.id, o.code)" +
") m " +
"JOIN OtherEntity o")
public List<MarkerEntity> entities(@Param("id") Long id)