'how to output 2 columns if i have 4 columns in postgresql and hibernate select c.name, c.email from Car c", Car.class, if

how to output 2 columns if i have 4 columns in postgresql using hibernate select c.name, c.email from Car c", Car.class if public class Car {

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

private String name;

private String email;

private String lastName;}


Solution 1:[1]

There are multiple ways you can do it One is using DTO Projection

Another is very simple one. Just return List<Object[]> and return a List of object array, you can store whatever you want.

I would suggest you to use DTO Projection if you have JPA version 2.1 or above else go with second option.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Asgar