1
我有一個實體:休眠 - 只獲取元素的最新版本中包含集合
@Entity
@DiscriminatorValue("News")
public class News extends TVProduction {
private int audience;
private Collection<Reportage> reportages;
public News() {
super();
setAudience(0);
}
@Column(name = "audience")
public int getAudience() {
return audience;
}
public void setAudience(int audience) {
this.audience = audience;
}
@OneToMany
@JoinTable(name = "Reportages_News",
joinColumns = @JoinColumn(name = "news_id"),
inverseJoinColumns = @JoinColumn(name = "reportage_id")
)
public Collection<Reportage> getReportages() {
return reportages;
}
public void setReportages(Collection<Reportage> reportages) {
this.reportages = reportages;
}
}
而且報告文學類看起來是這樣的:
@Entity
@Table(name = "Reportage")
public class Reportage {
private Long id;
private String subject;
private int version;
private String content;
private Reporter reporter;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
@SuppressWarnings("unused")
private void setId(Long id) {
this.id = id;
}
@ManyToOne
@JoinColumn(name = "reporter_fk")
public Reporter getReporter() {
return reporter;
}
public void setReporter(Reporter reporter) {
this.reporter = reporter;
}
}
我想要的只是在獲取新聞時獲取報告的最高版本。我試圖詮釋報告文學:
@Loader(namedQuery = "fetchFinal")
@NamedNativeQuery(name = "fetchFinal", query = "SELECT t.* FROM" +
"(SELECT id, subject, max(version) maxVersion, content, reporter" +
"FROM reportage GROUP BY id) x" +
"JOIN reportage t ON x.id = t.id AND x.maxVersion = t.version AND t.id = ?"
)
,但它不工作,他說:
初始SessionFactory的創建failed.org.hibernate.cfg.NotYetImplementedException:純天然的標量的查詢尚不支持
任何想法如何完成它?
同樣的錯誤 - 其實是我的第一次嘗試,但它不工作,要麼 –
我已經更新了我的答案 –
添加的標準方式 –