查詢我的JPA的數據庫(使用NetBeans,GlassFish的)用下面的查詢工作:JPA - 不是查詢成員查找bigint而不是日期?
//assume java.sql.Date d
Query q = em.createQuery("select b from Band b where :date MEMBER OF b.dates");
q.setParameter("date", d);
List bands = q.getResultList();
然而,當我改變了成員的不是會員,我得到以下服務器錯誤:
java.sql.SQLDataException: An attempt was made to get a data value of type 'DATE' from a data value of type 'BIGINT'.
Error Code: 20000
Call: SELECT t0.ID, t0.DTYPE, t0.EMAIL, t0.NAME, t0.PASSWORD, t0.BIOGRAPHY, t0.PHONENUMBER FROM SUPERUSER t0 WHERE (NOT EXISTS (SELECT DISTINCT t2.ID FROM SUPERUSER t2, Band_DATES t1 WHERE ((((t1.Band_ID = t0.ID) AND (? = t2.ID)) AND (t2.DTYPE = ?)) AND (t2.DTYPE = ?))) AND (t0.DTYPE = ?))
bind => [4 parameters bound]
任何幫助,將不勝感激。我正在使用sql.Date。
編輯:包括我帶實體
@Entity
@Table(name = "BAND")
public class Band extends SuperUser{
@Column(name="PHONENUMBER")
private String phoneNumber;
@Column(name="BIOGRAPHY")
private String biography;
@Column(name="DATES", columnDefinition = "DATE DEFAULT CURRENT_DATE")
@ElementCollection
private List<Date> dates = new <Date>ArrayList();
public Band(){}
public Band(String n, String e, String p, String ph_no, String bio){
super(n,e,p);
this.phoneNumber = ph_no;
this.biography = bio;
}
public void setPhoneNumber(String p)
{
this.phoneNumber = p;
}
public String getPhoneNumber()
{
return this.phoneNumber;
}
public void setBoigraphy(String b)
{
this.biography = b;
}
public String getBiography()
{
return this.biography;
}
public void setDate(Date d)
{
dates.add(d);
}
public void cancelDate(Date d)
{
while(dates.remove(d))
{}
}
public List getDates()
{
return dates;
}
}
怎樣才能獲取表的說明?
請張貼您的實體和表的描述。 – beerbajay 2012-02-26 00:25:01
實體發佈,我不知道如何獲得netbeans中的表格描述。 – Aido 2012-02-26 12:33:07
您如何期待從單列中獲得'List'?我假設日期存儲在另一個數據庫表中,在這種情況下,您需要'@ CollectionTable' –
beerbajay
2012-02-26 13:10:21