當我試圖設置在某個特定的Hibernate查詢字符串值,但我收到以下錯誤:爲什麼我得到這個錯誤?
java.sql.SQLDataException: An attempt was made to get a data value of type 'VARBINARY' from a data value of type 'VARCHAR'.
以下是哪裏出了問題來了休眠代碼:
公開名單getTransactions(長cardnum中,字符串類型){
Query q1 = factory.getCurrentSession().createQuery("FROM bank.persistence.entity.Transactions WHERE PK_CRED_CARD_ID=:CardID AND TRANSACTION_TYPE=:trType");
q1.setParameter("CardID", cardNum);
q1.setParameter("trType", type);
return q1.list();
}
當我試圖設置在某個特定的Hibernate查詢字符串值,但我收到以下錯誤:
java.sql.SQLDataException: An attempt was made to get a data value of type 'VARBINARY' from a data value of type 'VARCHAR'.
以下是哪裏出了問題來了休眠代碼:
公開名單getTransactions(長cardnum中,字符串類型){
Query q1 = factory.getCurrentSession().createQuery("FROM bank.persistence.entity.Transactions WHERE PK_CRED_CARD_ID=:CardID AND TRANSACTION_TYPE=:trType");
q1.setParameter("CardID", cardNum);
q1.setParameter("trType", type);
return q1.list();
}
以下是交易類:
package bank.persistence.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
public class Transactions implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int ID;
@Column(name = "TRANSACTION_TYPE")
private String transType;
@Column(name = "AMOUNT")
private float amt;
@Column(name = "DESCRIPTION")
private String desr;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "TRANSACTION_DATE")
private Date tranDate;
@ManyToOne
@JoinColumn(name = "PK_ACCT_ID")
private Account account;
@ManyToOne
@JoinColumn(name = "PK_CRED_CARD_ID")
private CreditCard credCard;
public String getTransType() {
return transType;
}
public void setTransType(String transType) {
this.transType = transType;
}
public String getDesr() {
return desr;
}
public void setDesr(String desr) {
this.desr = desr;
}
public CreditCard getCredCard() {
return credCard;
}
public void setCredCard(CreditCard credCard) {
this.credCard = credCard;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public float getAmt() {
return amt;
}
public void setAmt(float amt) {
this.amt = amt;
}
public Date getTranDate() {
return tranDate;
}
public void setTranDate(Date tranDate) {
this.tranDate = tranDate;
}
}// Class ends here
尊敬的ktj,您是否檢查過您正在設置的參數是否爲'空'值? – Amol 2013-03-19 07:04:56
@kjt - 檢查我的答案並嘗試一下。 – SudoRahul 2013-03-19 07:25:59
接受解決您的問題的答案,以便知道此問題已得到解答。 – SudoRahul 2013-03-19 08:20:42