NOW, 1.I need a sample code to show how to use this LocalSessionFactoryBean -sessionfactory.
2.Is a hibernate.cfg.xml needed?-where we usualy point to the mapping xmls.
Joined: Sep 17, 2003
I got this to work last week (so don't expect much help in followup questions), but here is what I know:
Everything I've seen seems to indicate that it's a bad idea to try to work with the sessionFactory directly, especially when you are going to need transaction support. I may be misreading (or don't know enough). Most people seem to use the HibernateTemplate, which I'll explain below.
Yes, of course you need a hibernate.cfg.xml. Spring is only abstracting Hibernate's components from your application for you. I found that you have to use the "configLocation" property of the sessionFactory for it to be pickedup:
It will be located on your classpath. I specify my object mappings in separate files, indicated in the main hibernate.cfg.xml.
I found it easiest to use the HibernateDaoSupport and HibernateTemplate class for my Hibernate-related DAOs. HibernateTemplate (a Hibernate class) is a property of the HibernateDaoSupport class (a Spring class). When you define your DAO beans, you'll inject the HibernateTemplate bean into your DAO.
First, you need to define some more beans in your spring Context:
Then you need to create your HibernateDAO, e.g.:
Then you need to define the DAO beans in Spring context file. There are two, one that acts as a proxy (for transaction management). This is the one that you'll application will call. The second is the reference to the actual DAO class:
BTW, the Spring framework plugins for Eclipse (or at least JBoss IDE), are really useful to visualize what you have configured.
Joined: Feb 13, 2009
I have done something like this following eclipse's spring and hibernate tutorial...
I am using postgres database.. lets assume I am using 10 tables in my database. .
I am trying to load them using...
beanFactory = new XmlBeanFactory(new ClassPathResource(
Now .. I am able to do all operations..like save update delete insert ..
The main problem is that .... when I load these 10 tables using my applicationContext.xml
There are 10 different process.. created in the task manager.. after going to all the process.. those 10 process .. are still there .. I think the connections are not closing down... for some reason ..
so when i open a new browser .. and try the same app.. another 10 postgres process adds up .. and so on ..
basically i need to close the connection ..