I'm using JavaEE to build a very simple Java full stack app, so I'm using JSF with Prime Faces 6.2 to render an xthml in the frontend and EJB, JPA with Hibernate and postgresql in the backend, however, When I set rowKey="#{person.id}" from a dataTable component from Prime Faces. Next exception is thrown.
"00:13:36,307 ERROR [io.undertow.request] (default task-55) UT005023: Exception handling request to /javaee-app/faces/listPersons.xhtml: javax.servlet.ServletException ... Caused by:java.lang.NullPointerException"
listPersons.xhtml
Prime Faces DataTable Component(opening tag and its attributes)
<p:dataTable id="persons"
value="#{personBean.persons}"
var="person"
editable="true"
rowKey="#{person.id}"
selection="#{personBean.personSelected}"
selectionMode="single">
The exception thrown that appears when trying to render the page is this.
However, if I set rowKey="#{person.name}" or even rowKey="#{person.email}" in stead of rowKey="#{person.id}" the problem disappears and xthml page is rendered correctly.
<p:dataTable id="persons"
value="#{personBean.persons}"
var="person"
editable="true"
rowKey="#{person.name}"
selection="#{personBean.personSelected}"
selectionMode="single">
with rowKey="#{person.name}" or rowKey="#{person.email}" xhtml page is rendered correctly"
MODEL/ENTITY
@Entity
@Table(name = "person")
@NamedQueries({
@NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),
@NamedQuery(name = "Person.findById", query = "SELECT p FROM Person p
WHERE p.id = :id")
, @NamedQuery(name = "Person.findByName", query = "SELECT p FROM
Person p WHERE p.name = :person_name")
, @NamedQuery(name = "Person.findByLastname", query = "SELECT p FROM
Person p WHERE p.lastname = :lastname")
, @NamedQuery(name = "Person.findByEmail", query = "SELECT p
FROM Person p WHERE p.email = :email")
, @NamedQuery(name = "Person.findByPhone", query = "SELECT p
FROM Person p WHERE p.phone = :phone")})
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 60)
@Column(name = "person_name")
private String name;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 60)
private String lastname;
@Basic(optional = false)
@NotNull
@Size(min = 1, max = 60)
private String email;
@Size(max = 60)
private String phone;
@OneToMany(mappedBy = "person", fetch = FetchType.EAGER)
private List<Users> users;
public Person() { }
public Person(Integer id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public List<Users> getUsers() {
return users;
}
public void setUsers(List<Users> users) {
this.users = users;
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
if (!(object instanceof Person)) {
return false;
}
Person other = (Person) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "Person [id = " + id + ", name=" + name
+ ", lastName=" + lastname + " email=" + email + ", phone=" + phone + "]";
}
Any idea to solve this problem guys? Thanks in advance
I'm also adding the images of the errors generated in the application server, in my case Wildfly 8.2