0

I am new in hibernate. I have followed this tuto on youtube : https://www.youtube.com/watch?v=FttfZok91Ek

At the end of the tuto, when I want to save an object on the database, I got this error message on my navigator :

javax.el.PropertyNotFoundException: /index.xhtml @11,78 action="#{data.addMember()}": Target Unreachable, identifier 'data' resolved to null.

To help you to understand, the error is located in the index.xhtml file. here is the content of the file.

<h:head>
    <title>Facelet Title</title>
</h:head>

<h:body>

    <h:form>
        <h:commandButton value="Add User" action="#{data.addMember()}" />
    </h:form>

</h:body>

The error is on the line which contains the "commandButton". After clicking on the button in the navigator, the action is to call the "data.java" class which contains a method named "addMember()". This method will add a member on the database.

Thank you in advance. Lamine

PS : if I am not clear on the text, don't hesitate to ask me some information.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Lamine BA
  • 89
  • 8
  • could you send the java sources and the full stacktrace? – cralfaro Mar 15 '16 at 15:14
  • Thank you @cralfaro. Here is my github repository which contains all the project source code : https://github.com/lemzoo/HibernateProject Thank You – Lamine BA Mar 15 '16 at 15:59
  • what i saw is that from the view you are trying to access to one service or data object, and this "data" object has not been initialized yet, then you got a nullPointerException. If you want to leard hiberante i would recomment another tutorial like, http://www.javatpoint.com/hibernate-with-annotation – cralfaro Mar 15 '16 at 16:16
  • Thank you @cralfaro. This is exactly what happen while executing the app. The data object is null. The data class doesn't contain a constructor. It just contains a one method allowing to add a member on the database. So while, I refer to the youtube tutorial, he doesn't get this error. Thank you for the tutorial. I'm using Netbeans IDE. – Lamine BA Mar 15 '16 at 16:23
  • great, enjoy the tutorial :) – cralfaro Mar 15 '16 at 16:31

1 Answers1

-1

The data object into the xhtml file was not initialized, then generate a null pointer.

cralfaro
  • 5,389
  • 3
  • 18
  • 25
  • Does someone know how can I initialize the data object on the xhtml file ? Thank you in advance. – Lamine BA Mar 15 '16 at 16:34
  • Is not real a good practice do that kind of things from the view, you should initialize in your controller, send to the view and use then in the view, but as i told you is not a good practice call from the view to some business logic entity, yours calls should go to the controller and the controller to the service – cralfaro Mar 15 '16 at 16:38
  • Next time, please post guesses as comments not as answers. – BalusC Mar 16 '16 at 08:32