JPA returning Object other than the class object type

2

The following query returns java.lang.ClassCastException: [Ljava.lang.Object; can not be cast to br.com.satisfacer.model.Customer

public List<Cliente> teste(Cliente cliente) {
    return manager.createQuery("from Cliente c join c.compras e where e.dataUltimaCompra > '01.08.2018'")
            .setMaxResults(100).getResultList();
}

My Bean

@SessionScoped
@Named
public class EmailModuleBean implements Serializable {
    private static final long serialVersionUID = 1L;

    @Inject
    private ClientePU clientePU;

    public void testes() {
        for (Cliente c : clientePU.teste(new Cliente())) {
            System.out.println(c.getNome());
        }
    }
}

My model:

@javax.persistence.Entity
@Table(name = "clientes")
public class Cliente implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "cod_cliente")
    private Long codigo;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "cod_profissao", referencedColumnName = "cod_profissao")
    private ClienteProfissao profissao;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
    private List<Compra> compras = new ArrayList<>();

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "cod_cliente", referencedColumnName = "cod_cliente")
    @NotFound(action = NotFoundAction.IGNORE)
    private ClienteOutrosDados outrosDados;
    
asked by anonymous 27.08.2018 / 00:48

1 answer

2

public List<Cliente> teste(Cliente cliente) {
    return manager.createQuery("select c from Cliente c join c.compras e where e.dataUltimaCompra > '01.08.2018'")
            .setMaxResults(100).getResultList();
}
    
27.08.2018 / 16:38