0

I have this JPA query which is used to select table with Specification Interface.

    public List<PaymentTransactions> findAll(Specification<PaymentTransactions> spec) {
        String hql = "select e from " + PaymentTransactions.class.getName() + " e";
        TypedQuery<PaymentTransactions> query = entityManager.createQuery(hql, PaymentTransactions.class);
        List<PaymentTransactions> paymentTransactions = query.getResultList();
        return paymentTransactions;
    }

What is the proper to select only the pessary columns from interface Specification using the above query?

org.springframework.data.jpa.domain interface public interface Specification<T> extends Serializable 
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808
  • are you using JPA repository in an interface – sam Oct 23 '18 at 15:29
  • Possible duplicate of [Spring JPA selecting specific columns](https://stackoverflow.com/questions/22007341/spring-jpa-selecting-specific-columns) – K.Nicholas Oct 23 '18 at 16:41

1 Answers1

0

I'm not sure if I got you right, but you can try this way

1) Create additional constructor with required arguments

package com.foo.bar;

public class PaymentTransactions {
    // column mapping and other properties are omitted
    private String requiredProp;
    private String optionalProp;

    public PaymentTransactions() {} // default no-arg constructor

    public PaymentTransactions(String required) {
       this.requiredProp = required;
    } 
}

2) And modify HQL query like

select new com.foo.bar.PaymentTransactions(e.requiredProp) from PaymentTransactions e
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42