這是我的JPA實體JPA:選擇隨機行
@Entity
@NamedQueries({
@NamedQuery(name = "Question.randQuestion", query = "SELECT q FROM Question AS q ORDER BY RANDOM")
})
@Table(name = "questions")
public class Question implements Serializable {
.....
}
的問題是:
日食給我一個錯誤此namedQuery。它說: 「標識變量'RANDOM'沒有在FROM子句中定義」
我也試過用RAND()而不是RANDOM和NEWID()。
謝謝。
'SELECT q FROM AS AS q ORDER BY RANDOM()'但它會以隨機順序返回所有行。 – vels4j
[隨機選擇行通過JPA]的可能重複(http://stackoverflow.com/questions/2459119/random-select-rows-via-jpa) –