我有2個實體:作者和專輯。 作者是OneToMany(mappedby =「author」) 相冊是ManyToOneJava Jpa查詢搜索實體相關ID
我試圖搜索相冊idAuthor傳遞。
下面的代碼:
public Collection<Album> findByIdAuthor(Long idAuthor, HttpServletRequest request) {
Collection<Album> album;
try {
album = em.createQuery("select a from Album a where a.author like :id").setParameter("id", idAuthor).getResultList();
} catch(Exception e) {
request.setAttribute("err", e.toString());
return null;
}
return album;
}
而且這裏有作者實體
@Entity
public class Author {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable=false)
private String name;
@Column
private int debut;
@Column(length=1000)
private String info;
@OneToMany(mappedBy="author")
private List<Track> tracks;
@OneToMany(mappedBy="author",cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
private List<Album> album;
public Author() {
super();
}
public Author(String name) {
super();
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getDebut() {
return debut;
}
public void setDebut(int debut) {
this.debut = debut;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public List<Track> getTracks() {
return tracks;
}
public void setTracks(List<Track> tracks) {
this.tracks = tracks;
}
public List<Album> getAlbum() {
return album;
}
public void setAlbum(List<Album> album) {
this.album = album;
}
@Override
public String toString() {
return "Autore [id=" + id + ", nome=" + name + ", dataDebutto="
+ debut + ", info=" + info + ", brani=" + tracks
+ ", album=" + album + "]";
}
}
但我收到此:org.apache.openjpa.persistence.ArgumentException:沒有元數據找到類型爲「java.lang.Integer」的類。該課程沒有增強。
爲什麼?
你可以檢查拼寫你的頭銜中有_Entityes_? –