我正在使用mysql,我正在尝试获取有序列表的行号,我回来了。但是@rownum:= @rownum + 1将使用本机查询返回null。
是否有其他方法可以通过使用JPA语法或更改MySQL查询来解决它。
使用评论信息更新查询。但是,将此对象设为“Hallmaster”对象将不会在Hallmaster中设置位置字段。如果我将它作为通用列表,它将包含正确的信息。
listHallmastaren = em.createNativeQuery("SELECT id, @position:=@position+1 AS position, " +
" e.name, e.score FROM HALLMASTER e, (SELECT @position:=0) t ORDER BY e.score desc", Hallmaster.class).getResultList();
添加了Hallmaster课程
public class Hallmaster implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; // still set automatically
@Transient
private Long position;
private String name;
private Integer score;
private static final long serialVersionUID = 1L;
public Hallmaster() {
super();
this.position = 0L;
this.name = "Nytt";
this.score = 0;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public long getPosition() {
return this.position;
}
public void setPosition(long position) {
this.position = position;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Integer getScore() {
return this.score;
}
public void setScore(Integer score) {
this.score = score;
}
}