Pobranie listy zgrupowanych wierszy z bazy danych

0

Witam,

Pobierając listę obiektów z bazy dostaje wyjatek :
java.lang.IllegalArgumentException: org.hibernate.QueryException: could not instantiate class [entities.DistributionChannel] from tuple
Spotkał się ktoś z takim problemem??

Query

 EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("JPAService");
        EntityManager em = entityManagerFactory.createEntityManager();
        
        em.getTransaction().begin();
        CriteriaBuilder builder = em.getCriteriaBuilder();
        
        CriteriaQuery<DistributionChannel> cq =  builder.createQuery(DistributionChannel.class);
        Root<DistributionChannel> root = cq.from(DistributionChannel.class);
        cq.multiselect(root.get("idReklamacji"), builder.max(root.get("dataZgloszenia")));
        cq.groupBy(root.get("idReklamacji"));
              
        Query query = em.createQuery(cq);
        System.out.println("QUUUEEERYYY: " + query.getResultList());

Przykład

@Inheritance(strategy = InheritanceType.JOINED)
public abstract class DistributionChannel implements Serializable {

    @Expose
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DC_SEQ")
    @SequenceGenerator(name="DC_SEQ", sequenceName="REKLAM_KANAL_SPRZEDAZY_SEQ", allocationSize=1)
    @Column(name ="RKS_ID", nullable=false)
    protected Long id;
    
    @Expose
    @Column(name ="RKS_REKLAMACJA_ID", nullable=false)
    @Size(max = 50)
    protected String idReklamacji;
    
    @Expose
    @Column(name ="RKS_DATA_ZGLOSZENIA", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    protected Date dataZgloszenia;

    @Expose
    @Column(name ="RKS_WYNIK_REKLAMACJI")
    protected int wynikReklamacji = 2;
    ....
    
    public DistributionChannel() {

    }
    
    public DistributionChannel(String idReklamacji, Date dataZgloszenia) {
        this.idReklamacji = idReklamacji;
        this.dataZgloszenia = dataZgloszenia;
    }
0

pierwszy wynik z gugla
You get a NullPointerException in the constructor, so the time argument that your query retrieves from the database is probably NULL

0

Gdyby to był nullpointer, to bym zauważył błąd.
Błąd był w tej linijce CriteriaQuery<DistributionChannel> cq = builder.createQuery(DistributionChannel.class);

1 użytkowników online, w tym zalogowanych: 0, gości: 1