I'm new at spring I've start reading a book from Wrox - Beginning Spring Framework.
I'm orientating from this book examples on creating my first data persisting application using maven, spring, hsqldb.
For several days I'm trying to create the application but no luck I'm getting frustrate I can't sleep . I know my post is going to be big but I'm hoping someone read it and help me make it work
I've created the model - class Album in directory /MyProject/src/main/java/model
I've also created Repository class in MyProject/src/main/java/dao directory called AlbumJpaRepository
I've created a execution file with main method AlbumDao.java in MyProject/src/main/java/dao directory
I've created two configuration XML files beans.xml and persistanceContext.xml in MyProject/src/main/resources directory
and the persistanceContext.xml
I'm starting the HSQLDB server successfully from the directory where my hsqldb-220.127.116.11.jar file is with the command
java -cp hsqldb-18.104.22.168.jar org.hsqldb.Server -database.0 temp -dbname.0 pix
and also successfully compiling the MyProject without any errors with maven. But when I try to execute the main class AlbumDao with the comand
mvn exec:java -Dexec.mainClass=dao.AlbumDao
I'm getting error ending like this
I've set it the dependencies in the pom.xml file I've also added sqltool.rc file in my home directory C:\Users\account that contains the following :
and still getting the same error
I may be on a wrong track and there is no way I can make it work with this approach or with this three softwares (Maven, Spring, HSQLDB ) for example I may also need a server Tomcat
If you are using Spring where are you creating your ApplicationContext?
I see in your main you just create instances of your objects directly with new, which means it isn't using Spring, just plain Java and therefore not using any of your SpringConfiguration. And therefore no JPA EntityManagerFactory being created and definitely no EntityManager being injected into your Repository. Therefore your EntityManager property in your Repository is not being set and that is a NullPointerException. And also no one is creating an instance your Repository so your dao method that uses it and calls one of its method throws a NullPointerException.
Try this in your DAO
Now another thing you should do with a Spring Application is to create interfaces for your classes and have them implement that interface and code to an interface.