我有一点问题:(当我尝试这样做时:
List<Dokumenty> dokumentyList =
(List<Dokumenty>)dokumentyDAO.getDokumentyByTrasy(((Trasy)routeComboBox.getSelectedItem()).getId());
for (Dokumenty dokumenty : dokumentyList){}
Run Code Online (Sandbox Code Playgroud)
然后我在for循环中得到错误:
java.lang.ClassCastException:[Ljava.lang.Object; 无法强制转换为database.entity.Dokumenty
我的DokumentyDAO看起来像这样:
public class DokumentyDAO{
private static volatile DokumentyDAO instance = null;
private DokumentyDAO() {}
public static DokumentyDAO getInstance() {
if (instance == null) {
synchronized (DokumentyDAO.class) {
if (instance == null) {
instance = new DokumentyDAO();
}
}
}
return instance;
}
public List<Dokumenty> getDokumentyByTrasy(long idTrasy){
Session session = HibernateUtil.getSessionFactory().openSession();
Query query = session.createQuery(
"FROM Dokumenty dokumenty "
+ "left join dokumenty.dostawy dostawy "
+ "left join dostawy.trasy trasy "
+ "left join dostawy.klienci klienci "
+ "where trasy.id = :idTrasy "
+ "and dostawy.aktywny = 'A' ");
// + "order by klienci.nrKlienta, klienci.nazwaKlienta, dokumenty.nrDok ");
query.setParameter("idTrasy", idTrasy);
return query.list();
}
}
Run Code Online (Sandbox Code Playgroud)
和Dokumenty:
public class Dokumenty implements java.io.Serializable{
private long id;
private Uzytkownicy uzytkownicy;
private Dostawy dostawy;
private String nrDok;
private String typDok;
private long JWydane;
private long eurWydane;
private long h1Wydane;
private long e2Wydane;
private long JZwrot;
private long eurZwrot;
private long h1Zwrot;
private long e2Zwrot;
private Date dataMod;
private char aktywny;
public Dokumenty() {
}
public Dokumenty(long id, Uzytkownicy uzytkownicy, Dostawy dostawy, String nrDok, String typDok, long JWydane, long eurWydane, long h1Wydane, long e2Wydane, long JZwrot, long eurZwrot, long h1Zwrot, long e2Zwrot, char aktywny) {
this.id = id;
this.uzytkownicy = uzytkownicy;
this.dostawy = dostawy;
this.nrDok = nrDok;
this.typDok = typDok;
this.JWydane = JWydane;
this.eurWydane = eurWydane;
this.h1Wydane = h1Wydane;
this.e2Wydane = e2Wydane;
this.JZwrot = JZwrot;
this.eurZwrot = eurZwrot;
this.h1Zwrot = h1Zwrot;
this.e2Zwrot = e2Zwrot;
this.aktywny = aktywny;
}
public Dokumenty(long id, Uzytkownicy uzytkownicy, Dostawy dostawy, String nrDok, String typDok, long JWydane, long eurWydane, long h1Wydane, long e2Wydane, long JZwrot, long eurZwrot, long h1Zwrot, long e2Zwrot, Date dataMod, char aktywny) {
this.id = id;
this.uzytkownicy = uzytkownicy;
this.dostawy = dostawy;
this.nrDok = nrDok;
this.typDok = typDok;
this.JWydane = JWydane;
this.eurWydane = eurWydane;
this.h1Wydane = h1Wydane;
this.e2Wydane = e2Wydane;
this.JZwrot = JZwrot;
this.eurZwrot = eurZwrot;
this.h1Zwrot = h1Zwrot;
this.e2Zwrot = e2Zwrot;
this.dataMod = dataMod;
this.aktywny = aktywny;
}
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
public Uzytkownicy getUzytkownicy() {
return this.uzytkownicy;
}
public void setUzytkownicy(Uzytkownicy uzytkownicy) {
this.uzytkownicy = uzytkownicy;
}
public Dostawy getDostawy() {
return this.dostawy;
}
public void setDostawy(Dostawy dostawy) {
this.dostawy = dostawy;
}
public String getNrDok() {
return this.nrDok;
}
public void setNrDok(String nrDok) {
this.nrDok = nrDok;
}
public String getTypDok() {
return this.typDok;
}
public void setTypDok(String typDok) {
this.typDok = typDok;
}
public long getJWydane() {
return this.JWydane;
}
public void setJWydane(long JWydane) {
this.JWydane = JWydane;
}
public long getEurWydane() {
return this.eurWydane;
}
public void setEurWydane(long eurWydane) {
this.eurWydane = eurWydane;
}
public long getH1Wydane() {
return this.h1Wydane;
}
public void setH1Wydane(long h1Wydane) {
this.h1Wydane = h1Wydane;
}
public long getE2Wydane() {
return this.e2Wydane;
}
public void setE2Wydane(long e2Wydane) {
this.e2Wydane = e2Wydane;
}
public long getJZwrot() {
return this.JZwrot;
}
public void setJZwrot(long JZwrot) {
this.JZwrot = JZwrot;
}
public long getEurZwrot() {
return this.eurZwrot;
}
public void setEurZwrot(long eurZwrot) {
this.eurZwrot = eurZwrot;
}
public long getH1Zwrot() {
return this.h1Zwrot;
}
public void setH1Zwrot(long h1Zwrot) {
this.h1Zwrot = h1Zwrot;
}
public long getE2Zwrot() {
return this.e2Zwrot;
}
public void setE2Zwrot(long e2Zwrot) {
this.e2Zwrot = e2Zwrot;
}
public Date getDataMod() {
return this.dataMod;
}
public void setDataMod(Date dataMod) {
this.dataMod = dataMod;
}
public char getAktywny() {
return this.aktywny;
}
public void setAktywny(char aktywny) {
this.aktywny = aktywny;
}
}
Run Code Online (Sandbox Code Playgroud)
Aby想法什么是错的?我用完了想法:/
你正在使用连接,所以Hibernate没有返回Dokumenty的列表,而是一个数组列表(想想行列表),每个数组的第一个条目是Dokumenty,第二个是dostawy,依此类推
| 归档时间: |
|
| 查看次数: |
9225 次 |
| 最近记录: |