• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Utdao.save(object) - java.lang.NullPointerException

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following error(full description below):

com.sun.faces.lifecycle.InvokeApplicationPhase execute WARNING: #{testeHibernate.save}: java.lang.NullPointerException javax.faces.FacesException: #{testeHibernate.save}



This happens when I upload the register button, won't let me enter the values in the database.

Class

UtilizadorDAO.java


UtilizadorDaoimpl.java



testeHibernate.java



Spring.xml


Error


web.xml



Thank you. (Excuse me if you have any programming error severe But I am learning)
 
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your sessionFactory might mot be initialized. Just add the following System.out.println to your method to see if it prints null.

 
Antonio Correia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes this null.
Where do I have to initialize the spring or class?

thanks ..
 
Marshal
Posts: 79029
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is that variable first declared?

And welcome to the Ranch
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you wiring your DAOs? For instance, if you were using annotations, you would write


but I don't see any annotations in your code.

Moving to Spring forum.
 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Antonio Correia wrote:Yes this null.
Where do I have to initialize the spring or class?

thanks ..




I am not sure I haven't been using Spring for a while but Spring should normally initialize it for you. You shouldn't have to create the sessionFactory yourself when using Spring. It is just a matter of getting it from Spring the right way.

Search Google for "getting hibernate session factory from Spring".

I found many links covering the subject and it seems like there is a few ways to do it.

Since you use this :LocalSessionFactoryBean:



Search for documentation specific on that but I recommend to let Spring manage the retreival and creation of the SessionFactory.

Google for:
"getting hibernate session factory from Spring when using LocalSessionFactoryBean".




 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:How are you wiring your DAOs? For instance, if you were using annotations, you would write


but I don't see any annotations in your code.

Moving to Spring forum.



Interesting, I would check what Knute suggests first.
 
Antonio Correia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that already solved but now of me this error did not know why

error


 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its says hibernate can find a definition for Classhiber.Utilizador

Do you have a package named Classhiber with a class Utilizador in it?

Note: package name should be all lower case.
 
Antonio Correia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes i have Utilizador at package.
I changed the name of package for classhiber.

 
A.J. Côté
Ranch Hand
Posts: 417
Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then make sure you use classhiber. not Classhiber. in your spring xml config file.

Java is case sensitive.

You seems to be using xml config files for hibernate instead of annotations.

In this case we used to use the following in hibernate config:



instead of:



I don't think your spring xml config file will work as is since you don't seem to be using annotated classes from an hibernate perspective. You are using mapping Ressources e.g. hbm.xml files.
 
Antonio Correia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you but continues to give error.

error


My Utilizador.hbm.xml



Spring



Excuse me if I am to be boring but I really want to learn.
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

javax.faces.FacesException: #{testeHibernate.save}: org.hibernate.MappingException: Unknown entity: classhiber.Utilizador


From your other classes imports, i see, that you package name is Classhiber, here you give classhiber, it is case sensitive, its a best practice to have package names in small letters, so change your package names accordingly.
 
Antonio Correia
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did not mentioned but I had already changed the name of the package and continues to give error
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic