I wan to fetch an object of entity using formula annotation
@Formula(value="(select ar from article ar where ar.id=1)")
private Article article;
Tried lot's of way. Pls help
Exception in thread "main" org.hibernate.MappingException: Could not determine type for: com.test.bean.Article, at table: Menu, for columns: [org.hibernate.mapping.Formula( (select ar from article ar where ar.id=1) )]
exception seems to say that it's not able to resolve type
Updating Entities
@Entity
public class Menu {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
// @Formula(value="article.id=1")
// @JoinColumnOrFormula(formula=@JoinFormula("(select ar from article ar where ar.id=1)"),column=@JoinColumn(insertable=false,updatable=false))
// @Transient
// @OneToOne(fetch=FetchType.EAGER,targetEntity=Article.class)
// @JoinColumn(insertable=false,updatable=false,columnDefinition="(select ar from article ar where ar.id=1)")
@Formula(value = "(SELECT ar.id from article ar where ar.id=1)")
// @OneToOne(targetEntity=Article.class,fetch=FetchType.EAGER)
// @Fetch(FetchMode.SELECT)
private Article article;
@Formula(value = "(SELECT count(*) from article ar where ar.id=1)")
private Integer count;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Article getArticle() {
return article;
}
public void setArticle(Article article) {
this.article = article;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
@Override
public String toString() {
return "Menu [id=" + id + ", article=" + article + ", count=" + count
+ "]";
}
}
@Entity(name = "article")
public class Article {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String uid;
private String content;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
return "Article [id=" + id + ", uid=" + uid + ", content=" + content
+ "]";
}
}
cfg also contain mapping.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…