Home Display some columns in Vaadin grid with JPA
Reply: 0

Display some columns in Vaadin grid with JPA

user3554 Published in May 22, 2018, 9:21 pm

I created Entity class:

package order;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.UUID;

@Table(name = "bo_order")
public class Order {
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;
    private String login;
    private Long internalNumber;
    private String food;
    private LocalDate dateOfOrder;
    private String orderNumber;

    public Order(){}

    public Order(String login)
        this.login = login;

    public Order(String login, Long internalNumber, String food, LocalDate dateOfOrder) {
        this.login = login;
        this.internalNumber = internalNumber;
        this.food = food;
        this.dateOfOrder = dateOfOrder;

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;

    public String generateOrderNumber()
        return UUID.randomUUID().toString();

    public String toString() {
        return "Order{" +
                "id=" + id +
                ", login='" + login + '\'' +
                ", internalNumber=" + internalNumber +
                ", food='" + food + '\'' +
                ", dateOfOrder=" + dateOfOrder +

added Repository to this:

package order;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface OrderRepository extends CrudRepository<Order, Long>{
    List<Order> findByLogin(String login);

    @Query(value="SELECT id, login FROM bo_order", nativeQuery = true)
    public List<Order> findAllPurchasers();

and try to display values from @Query in Grid:

package purchasers;

import com.vaadin.annotations.Title;
import com.vaadin.server.VaadinRequest;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.ui.*;
import order.Order;
import order.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;

@SpringUI(path = "/allpurchasers")
@Title("All today's purchasers")
public class AllPurchasersGUI extends UI {

    private final OrderRepository orderRepository;
    final Grid<Order> grid;

    public AllPurchasersGUI(OrderRepository pr) {
        this.orderRepository = pr;
        grid = new Grid<>(Order.class);

    protected void init(VaadinRequest vaadinRequest) {

    private void listPurchasers()

but I got an error org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [SELECT id, login FROM bo_order]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query and then

Caused by: org.postgresql.util.PSQLException: The column name data_ins was not found in this ResultSet.

I know data_ins is not in ResultSet because I don't want it there. I can display all values in Grid from bo_order with findAll but I want just id and login. How can I achive this? I also tried to make List<Object> instead of List<Order> but then I got problem with displaying then.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.315401 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO