Hibernate属性访问异常

时间:2017-06-09 10:54:20

标签: java hibernate java-ee

在我的数据库中,我有一个帐户表,我将“balance”(意大利语中的“Saldo”)行设置为默认空值。当我想要输入帐户时,在我的方法中有一个字段,我可以输入帐户的初始余额。账单开始进入时,hibernate给我这个错误:

WFLYEJB0034:对于方法公共抽象int ewl.proxima.ejb.ContoRemote.creaConto(java.lang.String,java.lang.String,double),组件ContoEJB上的EJB调用失败:javax.ejb.EJBException:javax.persistence .PersistenceException:org.hibernate.PropertyAccessException:为ewl.proxima.model.Conti.saldo的原始类型setter的属性[class ewl.proxima.model.Conti.saldo]赋值空值

这是我在康托课程中的方法setSaldo:

public Float getSaldo() {
    return this.saldo;
}

public void setSaldo(Float saldo) {
    this.saldo = saldo;
}

这是我从ejb调用的方法creaConto:

@Override
public int creaConto(String CF, String iban, double saldoIniziale) {

ContoDAOpers pcd = new ContoDAOpers(em);
    ewl.proxima.model.Conto c = pcd.getContoByCf(CF);
    c.setDataCreazione(new Date());
    c.setIban(iban);
    c.setSaldo((float) saldoIniziale);
    if(pcd.insertConto(c)) return 1;
    return -1;
}
来自ContoDAOpers的

insertConto:

public boolean insertConto(Conto c)
{
    entityManager.merge(c);
    return true;
}

我所有的Conto课程:

@Entity
@Table(name = "conti")
@NamedQuery(name="Conto.findAll", query="SELECT c FROM Conti c")
public class Conto implements Serializable {
private static final long serialVersionUID = 1L;

@Id
private int id;

private String codice_fiscale;

@Temporal(TemporalType.DATE)
private Date data;

private String iban;

private Float saldo;

//bi-directional many-to-one association to Movimento
@OneToMany(mappedBy="contoBean", orphanRemoval=true)
private List<Movimento> movimentos;

public Conto() {
}

public int getId() {
    return this.id;
}

public void setId(int id) {
    this.id = id;
}

public String getCf() {
    return this.codice_fiscale;
}

public void setCf(String cf) {
    this.codice_fiscale = cf;
}

public Date getDataCreazione() {
    return this.data;
}

public void setDataCreazione(Date dataCreazione) {
    this.data = dataCreazione;
}

public String getIban() {
    return this.iban;
}

public void setIban(String iban) {
    this.iban = iban;
}

public Float getSaldo() {
    return this.saldo;
}

public void setSaldo(Float saldo) {
    this.saldo = saldo;
}

public List<Movimento> getMovimentos() {
    return this.movimentos;
}

public void setMovimentos(List<Movimento> movimentos) {
    this.movimentos = movimentos;
}

public Movimento addMovimento(Movimento movimento) {
    getMovimentos().add(movimento);
    movimento.setContoBean(this);

    return movimento;
}

public Movimento removeMovimento(Movimento movimento) {
    getMovimentos().remove(movimento);
    movimento.setContoBean(null);

    return movimento;
}

}

致电creaConto:

protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException 
    {
        String prov = request.getParameter("provenienza");
        if(prov.equals("insertConto"))
        {
            String cfDip = request.getParameter("cfDip");
            String iban = request.getParameter("iban");
            if(iban.replaceAll(" ", "").equals(""))
            {
                request.setAttribute("error", true);
                request.setAttribute("dipendenti", getContiVuoti());

getServletContext().getRequestDispatcher
("/insertConto.jsp").forward(request, response);
                return;
            }

            int i = 0;
            try
            {
                double saldo = 
Double.parseDouble(request.getParameter("saldo").
replaceAll(",", "."));
                i = contoEJB.creaConto(cfDip, iban, saldo);
            }
            catch(NumberFormatException e)
            {
                e.printStackTrace();
                i = -1;
            }

            if(i == -1 || i == -10)
                request.setAttribute("error", true);
            else
                request.setAttribute("success", true);

            request.setAttribute("dipendenti", getContiVuoti());

getServletContext().getRequestDispatcher
("/insertConto.jsp").forward(request, 
response);
            return;
        }

0 个答案:

没有答案