我正在尝试从表中检索单个列,但出现有关返回类型的编译错误。
数据库
select oComment from comment where oNote = note and version > 0;
我有Comment桌子和Note桌子。评论表有comment, note and version列。评论本身就是一个注释。现在我想检索版本大于 0 的注释的所有评论。但是在这里我只想要注释类型的注释列。
Comment.java
@Entity
@Table(name="comment")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="comments")
public class Comment implements Serializable {
private static final long serialVersionUID = -4420192568334549165L;
public Comment() {
}
@Id
@OneToOne
@JoinColumn(name="commentuuid",referencedColumnName="noteuuid")
private Note oComment;
@Id
@OneToOne
@JoinColumn(name="noteuuid",referencedColumnName="noteuuid")
private Note oNote;
}
Note.java
@Entity
@Table(name = "note")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="notes")
public class Note implements Serializable{
private static final long serialVersionUID = 4089174391962234433L;
@Column(name="title")
private String m_szTitle;
@Column(name="htmlcontent")
private String m_sbHtmlContent;
@Column(name="textcontent")
private String m_sbTextContent;
@Id
@Column(name="noteuuid", columnDefinition="varchar(36)")
private String noteUuid;
}
自定义存储库方法
public List<Note> findAllByNote(Note oNote, int iOffset, int iResultSize) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Comment> cq = cb.createQuery(Comment.class);
Root<Comment> oComment = cq.from(Comment.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(cb.equal(oComment.get("oNote"), oNote));
predicates.add(cb.greaterThan(oComment.get("version"), 0));
江户川乱折腾
千巷猫影
HUH函数
SMILET
相关分类