0

我有两个类有关系@OneToMany(支付和拆分)下面的代码:

@Entity
@Table(name="pagamento")
public class Pagamento implements Serializable { //Class Pay

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="idpagamento")
private int id;
...
@ManyToOne()
@JoinColumn(name="idconta")
private Divida coddivida;

及以下类拆分

@Entity
@Table(name="divida")
public class Divida implements Serializable{

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idconta")
private int id;
...
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER,                   mappedBy="coddivida",        targetEntity = Pagamento.class)
private List<Pagamento> pagamento;

我搜索了下面的数据代码:

 public List<Divida> getDividas(){
    return getCleanListOfObjects(Divida.class,"from Divida divida");
}

我试图在数据表中显示如下:

<p:dataTable id="paneluser" value="#{dividaFaces.listofDivida}" var="divida" selection="#{dividaFaces.selectedDivida}"
                     rowKey="#{divida.id}" selectionMode="sigle" emptyMessage="Não existe Dívida" paginator="true" rows="10">
            <f:facet name="header">
                Panel de Dívidas Cadastradas
            </f:facet>
            <p:column headerText="Descricão">
                #{divida.descricao}
            </p:column>
            <p:column id="pagar" headerText="Tela de Pagamento">
                <p:commandButton value="Pagar">
                    <p:ajax oncomplete="pagetela.show()" update="telapgamento"/>
                </p:commandButton>
            </p:column>
            <f:facet name="footer">
                Financé v#{sistema.VERSION}
            </f:facet>
        </p:dataTable>

但它给出了以下错误:

Hibernate: 
 /* 
from
Divida divida */ select
    divida0_.idconta as idconta0_,
    divida0_.datadeinicio as datadein2_0_,
    divida0_.descricaodespesa as descrica3_0_,
    divida0_.empresa as empresa0_,
    divida0_.exercicio as exercicio0_,
    divida0_.observacao as observacao0_,
    divida0_.operacaobancaria as operacao7_0_,
    divida0_.parcela as parcela0_,
    divida0_.tipolancamento as tipolanc9_0_,
    divida0_.vencimento as vencimento0_ 
from
    divida divida0_
Lista de Dividas: []
Hibernate: 
 /* 
from
Divida divida */ select
    divida0_.idconta as idconta0_,
    divida0_.datadeinicio as datadein2_0_,
    divida0_.descricaodespesa as descrica3_0_,
    divida0_.empresa as empresa0_,
    divida0_.exercicio as exercicio0_,
    divida0_.observacao as observacao0_,
    divida0_.operacaobancaria as operacao7_0_,
    divida0_.parcela as parcela0_,
    divida0_.tipolancamento as tipolanc9_0_,
    divida0_.vencimento as vencimento0_ 
    from
    divida divida0_
    Mar 26, 2013 8:34:31 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
    SEVERE: Error Rendering View[/menu/principal.xhtml]
    java.lang.ClassCastException: br.com.finance.model.Divida cannot be cast to java.util.List
at    org.primefaces.component.datatable.DataTable.findSelectedRowKeys(DataTable.java:977)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:624)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:234)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:196)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:881)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:851)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

谁能帮我?

4

1 回答 1

0

您正在使用 selectionMode="sigle"。请注意单曲中缺少的“n”。您在这里遇到的异常与 Hibernate 无关。

于 2013-03-26T23:57:06.147 回答