[color=#FF0000]问题描述:我想查询Tmodel的记录,但是我想要查询的结果按照评论的次数升序或降序排序。[/color]//////////////////////////////////////Tmodel 类的定义///////////////////////////////////////////////
@Entity
@Table(name = "tb_tmodel")
public class Tmodel implements java.io.Serializable {
private static final long serialVersionUID = -281504951906599269L;
private Long id;
private String name;
private List<TmodelComment> tmodelComments = new ArrayList<TmodelComment>(0); public Tmodel() {
} @Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Long getId(){
return this.id;
} public void setId(Long id){
this.id = id;
}@Column(name = "name", nullable = false)
public String getName() {
return this.name;
}public void setName(String name) {
this.name = name;
}@OneToMany(cascade=CascadeType.REMOVE,fetch=FetchType.LAZY,mappedBy="tmodel")
@OrderBy("id desc")
public List<TmodelComment> getTmodelComments() {
return tmodelComments;
}public void setTmodelComments(List<TmodelComment> tmodelComments) {
this.tmodelComments = tmodelComments;
}
}///////////////////////////////TModel的评论类:TmodelComment类/////////////////////////////////
@Entity
@Table(name = "tb_tmodel_comment")
public class TmodelComment implements Serializable {
private static final long serialVersionUID = -7131379575770195913L;
private Long id;
private String comment;
private Tmodel tmodel;public TmodelComment() {
}@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Long getId() {
return id;
}public void setId(Long id) {
this.id = id;
}@Column(name = "comment", length = 1024, nullable = false)
public String getComment() {
return comment;
}public void setComment(String comment) {
this.comment = comment;
}@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tmodel_id", nullable = false)
public Tmodel getTmodel() {
return tmodel;
}public void setTmodel(Tmodel tmodel) {
this.tmodel = tmodel;
}}
@Entity
@Table(name = "tb_tmodel")
public class Tmodel implements java.io.Serializable {
private static final long serialVersionUID = -281504951906599269L;
private Long id;
private String name;
private List<TmodelComment> tmodelComments = new ArrayList<TmodelComment>(0); public Tmodel() {
} @Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Long getId(){
return this.id;
} public void setId(Long id){
this.id = id;
}@Column(name = "name", nullable = false)
public String getName() {
return this.name;
}public void setName(String name) {
this.name = name;
}@OneToMany(cascade=CascadeType.REMOVE,fetch=FetchType.LAZY,mappedBy="tmodel")
@OrderBy("id desc")
public List<TmodelComment> getTmodelComments() {
return tmodelComments;
}public void setTmodelComments(List<TmodelComment> tmodelComments) {
this.tmodelComments = tmodelComments;
}
}///////////////////////////////TModel的评论类:TmodelComment类/////////////////////////////////
@Entity
@Table(name = "tb_tmodel_comment")
public class TmodelComment implements Serializable {
private static final long serialVersionUID = -7131379575770195913L;
private Long id;
private String comment;
private Tmodel tmodel;public TmodelComment() {
}@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
public Long getId() {
return id;
}public void setId(Long id) {
this.id = id;
}@Column(name = "comment", length = 1024, nullable = false)
public String getComment() {
return comment;
}public void setComment(String comment) {
this.comment = comment;
}@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "tmodel_id", nullable = false)
public Tmodel getTmodel() {
return tmodel;
}public void setTmodel(Tmodel tmodel) {
this.tmodel = tmodel;
}}
解决方案 »
- list和set的contains()方法问题
- 怎么把html页面信息通过javascript读写到xml中,要求xml自动生成
- java调用com组件 vb的两个byref参数赋任意一个值均为相同
- activeMQ取消息的问题
- struts2 checkboxlist 选中问题
- HibernateDaoSupport里用什么方法能进行多条件查询
- eclipse和myeclipse有什么联系和区别?
- 如何按条件读取数据库中的数据并在窗体上的JComboBox里显示。
- [全部分数]SQLServer JDBC 驱动的问题.
- 求一个效果的实现方案!!!急
- struts2 表单提交问题
- jQuery ajax 火狐fireFox 上的返回值是object XMLDocument
select model
from Tmodel model
join model.tmodelComments comment
group by model
order by count(comment) asc