aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate save object problem ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate save object problem !" Watch "hibernate save object problem !" New topic
Author

hibernate save object problem !

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
hi, good day , i'm new in hibernate , i would like to taste on this famous technology in trend ,

i have a mapping file as follow :


and i have a manager class which use for to save object as follow :


i also have a DAO implementation class to save the object as follow :


problem :
when i run the manager class, which i suppose use to start my testing, which prompt me the error as follow

error code :
aused by: java.lang.NullPointerException
at pojo.dao.TestDAOImpl.insert(Unknown Source)
at Manager.EventManager.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:202)
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:134)

can someone pls guide me, what i have miss out ? thank you
[ October 25, 2005: Message edited by: Nakata kokuyo ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Your no-args constructor in TestDAOImpl is dangerous. Your insert method needs a HibernateDM instance, but TestDAOImpl doesn't create one if none is passed to it.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
thanks paul for comments, now my manager class look as follow, but it give me same error



error code :

java.lang.NullPointerException
at org.hibernate.cfg.Configuration.addDirectory(Configuration.java:525)
at hibernate.HibernateSingleton.<init>(Unknown Source)
at hibernate.HibernateSingleton.getInstance(Unknown Source)
at hibernate.DAOLocator.setup(Unknown Source)
at hibernate.DAOLocator.<init>(Unknown Source)
at hibernate.DAOLocator.getInstance(Unknown Source)
at hibernate.DAOLocator.getInstance(Unknown Source)
at Manager.EventManager.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

and also, why you say no -arg contructor give danger in my case , i thought we need it for every concrete class of DAO implementation (TestDAOImpl)?

thank you
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
A quick check of the Configuration.addDirectory() method indicates a NPE could be thrown if the parameter dir is null or the dir.listFiles() returns a null.



I would look at the constructor for hibernate.HibernateSingleton to verify the directory being passed to the Configuration object is not null, exists and you have permissions to it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


and also, why you say no -arg contructor give danger in my case , i thought we need it for every concrete class of DAO implementation (TestDAOImpl)?

No sense writing a class that requires an instance of HibernateDM, then allowing an object of that class to be created without an instance of HibernateDM.
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
hi, scott and paul, my hibernateDM look like this



when i compile with Ants , it look fine ...anyone see the problem here ?

and i use the following ant script to run the manager class



anyone know the problem ?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Any exceptions raised constructing your singleton? The way it is written it shouldn't be able to reach addDirectory() if the file is null.

(Any reason why you are getting your configuration this way, as opposed to using the configure method on the Configuration object? )
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
Is file null when you call:



??
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
hi, scott n paul , i have not found any exception ,

when ant run the manager class, it simply generate

D:\Documents and Settings\Alvin\IdeaProjects\Testing\build\classes\mapping

as build path

and i put the mapping folder into

D:\Documents and Settings\Alvin\IdeaProjects\Testing\src\mapping

as refer my current hibernateDM



the result of debug for log.debug("fdirname ====>" + fdirName.getFile());
is DEBUG (?:?) - fdirname ====>/D:/Documents%20and%20Settings/Alvin/IdeaProjects/Testing/build/classes/mapping/

whereas log.debug("file path===> " + file.getPath() + "==== file name " + file.listFiles()) is

DEBUG (?:?) - file path===> D:\Documents%20and%20Settings\Alvin\IdeaProjects\Testing\build\classes\mapping==== file name null


the hbm.xml files definitely there, but am i getting the wrong folder ?

and also to create hibernate like this, will allow me not to put every single mapping statement in hibernate.properties file

thank you again for comments , have a nice day
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
I noticed that your path name has encoded spaces (%20). Try using a path that doesn't contain encoding.
Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
thanks paul and scott ...i finally figure out the problem, i just move the whole project to other directory rather than under document then it solve ...thanks for your hard work

but i have another issue to come out in other thread
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate save object problem !