一段时间以来,我在eclipselink映射中遇到问题。

我有两个课程,Acordo和ValorAcordo。

所以我有

@ Entity
    @ Table ( name = " TB_ACORDO " , schema = " JUR " )
    @ NamedQueries ( {
    @ NamedQuery ( name = " sql1 "
    query = " SELECT a.NU_ACORDO , a.NU_MOVIMENTACAO , v.NU_CONTRATO "
    + "FROM Acordo"
    + " INNER JOIN ValorAcordo v"
    + "ON a.NU_ACORDO = v.NU_ACORDO "
    + " WHERE = a.NU_MOVIMENTACAO : nu_movimentacao " )
    } )
    public class Acordo implements Serializable {

    private static final long serialVersionUID = - 6202293050832719017L ;

    @ Id
    @ GeneratedValue ( strategy = GenerationType.IDENTITY )
    private Long NU_ACORDO ;

    private Long NU_MOVIMENTACAO ;
    private Long VR_TOTAL ;

    @ OneToOne ( fetch = FetchType.LAZY )
    private ValorAcordo valorAcordo ;
    // ***




@ Entity
@ Table ( name = " TB_VALOR_ACORDO " , schema = " JUR " )
public class ValorAcordo implements Serializable {
private static final long serialVersionUID = 3024868010888830368L ;

@ Id
@ GeneratedValue ( strategy = GenerationType.IDENTITY )
private Long NU_VALOR_ACORDO ;
private Long NU_ACORDO ;
private Long NU_CONTRATO ;
private Long NU_PARTE ;
private Long QT_PARCELA ;
private Long VR_ACORDO ;

@ Temporal ( TemporalType.TIMESTAMP )
private Date DT_PRIMEIRA_PARCELA ;
@ Temporal ( TemporalType.TIMESTAMP )
private Date DT_ULTIMA_PARCELA ;

@ OneToOne ( fetch = FetchType.LAZY )
private acordo;
// ***


当我跑步时

Query q = em.createNamedQuery ( " sql1 " Acordo.class )
. setParameter ( " nu_movimentacao " 3103461 );
List <Acordo> q.getResultList list = ( ) ;


EclipseLink向我返回以下错误:

Exception in thread " main" java.lang.ClassCastException : [ Ljava.lang.Object ; can not be cast to br.victor.des.bean.Acordo
at br.victor.des.main.MainAcordo.main ( MainAcordo.java : 46)


有任何想法吗?

我认为这是一个映射问题,但是找到了链接eclipsebug,其中一些开发人员报告了此错误。但是他们通过简单的查询就遇到了这个问题,只有当我使用JOIN时,我才会遇到这个问题!

谢谢

最佳答案

查询sql1定义为“ SELECT a.NU_ACORDO,a.NU_MOVIMENTACAO,v.NU_CONTRATO ..”-它从Acordo中选择3个字段,而不是完整实例,因此JPA为您提供了包含3个对象的对象数组列表每行的值。如果要完整实体,则将查询更改为“ SELECT A FROM Acordo a ...”。

10-06 08:53