Search code examples
javaspring-mvcnhibernate-mappingjsp-tags

Javax.el.PropertyNotFoundException: Property 'ticket_id' not found on type java.lang.Integer


The datatype for TICKET_ID column is int in DB. Still the problem persists.Set the getter/setters public too.

Model

@Id
@Column(name = "TICKET_ID")
private Integer ticket_id;



public Integer getTicket_id() {
    return ticket_id;
}

public void setTicket_id(Integer ticket_id) {
    this.ticket_id = ticket_id;
}


@Column(name = "PRIORITY")
private String priority;

HQL

    Session session = sessionFactory.openSession();

    String hql = "Select ticket_id from Ticket";

    @SuppressWarnings("unchecked")
    List<Ticket> ticketList = session.createQuery(hql)
            .list();
    session.close();
    return ticketList;

JSP

<th>Category</th>
                    </tr>
                    <c:forEach items="${ticketList}" var="usr">
                        <tr>
                            <td><c:out value="${usr.ticket_id}" /></td>
                            <td>Priority</td>

Exception

javax.el.PropertyNotFoundException: Property 'ticket_id' not found on type java.lang.Integer


Solution

  • Your query is

    select ticket_id from Ticket
    

    That query returns a List<Integer> containing all the ticket IDs from the ticket table, not a List<Ticket>. If you want a list of tickets, the query should be

    select t from Ticket t
    

    You should also strive to recpect the Java naming conventions: ticketId, not ticket_id.