Can not Fetch Data with JPQL using Postgres Database Spring MVC

By : soewin

I am trying to develop SpringMVC framework, everything working fine but when I run my codes, data are not fetched from Postgres database using JPQL.

domain model class

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
    import javax.persistence.Version;

    @Table(name = "Contact")
    @NamedQuery(name="Contact.findAll", query="select c from Contact c")

    public class Contact implements Serializable {

        private Long id;
        private int version;
        private String firstName;
        private String lastName;
        private String description;
getter and setter defined

Repository Class

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.apress.prospring3.ch17.domain.Contact;
public class ContactRepository implements CrudRepository {
    private EntityManager manager;

    public List<Contact> findAll() {
        List<Contact> contact = manager.createNamedQuery("Contact.findAll", 
        return contact;

Controller Class

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.apress.prospring3.ch17.domain.Contact;
import com.apress.prospring3.ch17.service.ContactService;

public class ContactController {

    ContactService contactService;

    @RequestMapping(method = RequestMethod.GET)
    public String list(Model uiModel) {
        List<Contact> contacts = contactService.findAll();
        uiModel.addAttribute("contacts", contacts);
        return "contacts/list";


Front View (list.jspx)

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:jsp=""
    xmlns:joda="" version="2.0">
    < contentType="text/html;charset=UTF-8" />
    <jsp:output omit-xml-declaration="yes" />
    <h1>Contact Listing</h1>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Birth Date</th>
                <c:forEach items="${contacts}" var="contact">

Server Logs

Hibernate: select contact0_.ID as ID1_0_, contact0_.DESCRIPTION as DESCRIPT2_0_, contact0_.FIRST_NAME as FIRST_NA3_0_, contact0_.LAST_NAME as LAST_NAM4_0_, contact0_.VERSION as VERSION5_0_ from Contact contact0_

Jan 24, 2016 2:19:14 PM org.apache.jasper.compiler.TldLocationsCache tldScanJar INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned where no TLDs were found. Skipping JAR scanning can improve startup time and JSP compilation time.


enter image description here

Postgres DataBase data enter image description here

Please correct me what I am missing. Thank you so much.

By : soewin


Finally I realized what I have missed.

I forget to declare empty constructor for my model class.

public class Contact implements Serializable {

        private Long id;
        private int version;
        private String firstName;
        private String lastName;
        private String description;
public Contact(){} // This invoke to model with Entity class and interact with Database
getter and setter defined
By : soewin

This video can help you solving your question :)
By: admin