Friends, I though it may useful to some body who is looking for such information... Introduction As most of us well aware of Hibernate and Spring frameworks, I am not getting into much of introduction part. However in short,
Hibernate � A popular & successful ORM tool � Abstracting the underlining JDBC programming � Portable to any supported database with minor configuration changes � Provides Transaction Management etc�.
Spring � Implementation Inversion of Control (IOC) design pattern. � Abstraction to Aspect Oriented Programming (AOP). � Creates the java object beans from an application context xml (spring configuration file) I would like to walk you through a running example how they both work together� Please take a look at the below xml..
Header part of spring configuration xml includes spring-bean.dtd
Loading Hibernate properties: Hibernate properties can be loaded using Spring�s PropertyPlaceholderConfigurer class. Provide hibernate.properties file location as value. If the file placed under any other directory other than WEB-INF directory, use classpath: expression to let the Spring to look for the file in available classpath.
Defining a DataSource: Use JndiObjectFactoryBean class to define the data source by providing JNDI binding name.
Defining a Session Factory: Hibernate session factory can be defined using LocalSessionFactoryBean class, provides an integration point to Hibernate from Spring. Here we need to provide data source information and hibernate mapping files (.hbm.xml). Transaction factory class, hibernate supports org.hibernate.transaction.JDBCTransactionFactory - delegates to database (JDBC) transactions (default) org.hibernate.transaction.JTATransactionFactory - delegates to container-managed transaction if an existing transaction is underway in this context (e.g. EJB session bean method), otherwise a new transaction is started and bean-managed transaction are used. org.hibernate.transaction.CMTTransactionFactory - delegates to container-managed JTA transactions
Transaction Lookup class: It depends on application server on which the application is running, here I am using WebSphere Application Server related one. Special columns if there are any column defined CLOBs, those can handled using default implementation provided spring. Here as an example I am using CLOB handler.
Defining a Transaction Manager: By providing the above defined session factory, a transaction manager needs to be defined as below.
It might be a quick, not much detailed enough as I covered only basic configuration. Please let write your inputs/comments, I will try to add some more details�.. [ June 26, 2008: Message edited by: Yellappa Adepu ]
Hello, I am trying to add hibernate to my existing spring application.I am using spring 2.5,hibernate annotations 3.2, mysql and tomcat I have written applicationcontext.xml and hibernate.cfg.xml. But I am getting this error
Context initialization failed.org.springframework.beans.factory.beandefinitionstoreexception: IOException parsing XML document from servletcontext resource [/web-inf/applicationcontext.xml] nested exception is java.io.FilenotfoudException: could not open servletcontext resource [/web-inf/applicationContext.xml]