0

I'm using hibernate with spring and i can't get some data from my database, i'm trying to list user objects in a primefaces p:datatable.

In my console it throws the exception in FillUsersList : java.lang.NullPointerException Erreur dans usersList

(spring 3.2 , hibernate 4.2 , jsf 2.1 )

Managedbean :

@Autowired
    UserService userService;
// Used to fetch all records  
@PostConstruct  
public void fillUsersList(){                   
try{  
    usersList = userService.getAllUsers();  
}catch(Exception e){  
System.out.println(e+"Erreur dans usersList");  
}  
} 


        public List<DemUser> getUsersList() {
            return usersList;
        }
        public void setUsersList(List<DemUser> usersList) {
            this.usersList = usersList;
        }

DAO :

@SuppressWarnings("unchecked")
public List<DemUser> getAllUsers() {
    try {
        return sessionFactory.getCurrentSession().createQuery("from DemUser")
                .list();
 } catch (RuntimeException re) {
    System.out.printf("*** return All users failed", re);
     throw re;
 }
}

JSF :

<p:dataTable var="u" value="#{UserBean.usersList}" >
    <p:column headerText="Name">
        <h:outputText value="#{u.nameUser}" />
    </p:column>
</p:dataTable>
Kukeltje
  • 11,924
  • 4
  • 19
  • 44
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Kukeltje May 17 '20 at 08:54
  • Since you're facing a NPE, you need to debug which item is null. In your case it seems your Autowired service isn't initialized, so your Managedbean isn't in Spring path scan, or it's just missing the correct Annotation. – WoAiNii May 17 '20 at 08:56
  • If you can't get data from the database, it is jpa hibernate or jdbc related, not jsf. – Kukeltje May 17 '20 at 09:00

0 Answers0