I'm a newbie in the Spring enviroment but I have been reading a lot about how it works.
By now I'm doing a simple project with Hibernate, so here is where things goes interesting.
In the servlet-context file I have something like this:
And I have an abstract class (In order to extend it over all my DAO implementations) that looks like this:
Doing this when I need create a new method, all that I do in my other DAO is create a local variable with type Session and set the getSessionFactory().getCurrentSession().
I have been testing the connection credentials in order to validate the dataSource, anyway always that I try to obtain the Session I got null
Is there any particular reason you are reinventing wheels? Why not just use HibernateDAOSupport?
Can you post your DAO bean? How are you getting an instance of the DAO? I don't see it being declared in your spring context. Is it loaded by Spring. Note that spring autowiring works only in beans loaded by spring. If you are loading your own beans, Spring isn't going to inject dependencies into it.
Hi Jayesh, in the other post I show a Dao who extends the GenericDao and the way how I try to call the sessionFactory.
A brief summary about what I'm doing is: creating a bean in the XML using the Spring class org.springframework.orm.hibernate4.LocalSessionFactoryBean, which should create a new session factory object, so in that order I use the Autowired annotation to inject it to my GenericDao, but always getting null, aparently it is not being created.
Again. Can you post the code where you are calling the DAO. I understand you posted the code for the DAO. Please read this carefully. Post the code that is calling the DAO
Also, snippets of stack trace don;t help. Please post the complete stack trace. All I can see is that it seems you are trying to call the DAO from an Axis web service. I am interested in knowing how you got the instance of the DAO in the Axis web service.
You should never use new to create a bean that has Spring annotations. Spring can process the autowire annotation in a bean only if it creates the bean itself. If you create a bean, then all them members with Autowire annotation on them will always be null
Now, if your "intermediate" class has an member of type myDAO with an Autowire annotation, then you need to make sure, you do not do new on that intermediate class. It's hard to tell what exactly you are doing because you refuse to post the code that you are being asked to post.
Please don't tell me that. The stack trace tells a lot more than you think. You don't know how to read the stack trace. It's annoying to ask you the same thing 3 times, and get no response. Or worse, "Oh no.. don;t worry about it". Even the Axis bit is relevant. Because I want to see how you are initializing the DAO, and somehow your Axis web service is getting an instance of the DAO, and I want to see how you are getting the instance.
Really, if you want help you should post the SSCCE
I got it, but still is not working, getting null when I call my class via Autowired.
This is what I'm calling via Axis
Don't get upset if I say that don't worry aout Axis or for what else can be saying the stack trace, you know that when is throwed an exception is a kind of inverse cascade, so it always point to this class with the Null
I did everything again, calling my method with the Controller now it works, but I found that using the web service don't.
Apparently when calling the WSDL is created an instance and that is making everything Null.
Do you know how can I do this? because in other way I will have to create manually my SessionFactory objet using a kind of Hibernate helper.
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Devious Experiments for a Truly Passive Greenhouse!