We can select specific columns by writing custom @Query methods in our repository interface. However, I do not want to write so many methods for different properties.
I tried this, but it always returns the whole object.
public class MySpecifications { public static Specification<MyInfo> propertiesWithId(final String[] properties, final Object id, final String idProperty) { return new Specification<MyInfo>() { @Override public Predicate toPredicate(Root<MyInfo> root, CriteriaQuery<?> query, CriteriaBuilder cb) { query = cb.createTupleQuery();
used as:
MyInfo findOne(Specification(properties,idValue, idProperty));
Is it correct? Where is the mistake?
java spring spring-data spring-data-jpa jpa
Chinmay
source share