Hi Arul,
Thank you for the reply and any help you can offer.
As I stated I do have a bean named transactionManager.
Here is my config.
Code:
package com.project.core.dao;
import java.util.Properties;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.config.java.annotation.Bean;
import org.springframework.config.java.annotation.Configuration;
import org.springframework.config.java.plugin.tx.AnnotationDrivenTx;
import org.springframework.config.java.support.ConfigurationSupport;
import org.springframework.config.java.util.DefaultScopes;
import org.springframework.jndi.JndiObjectFactoryBean;
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import com.project.db.dao.MyJdbcTemplate;
/**
* * Java Configuration for Hibernate, Database and JPA
*
*/
@AnnotationDrivenTx
@Configuration
public class Config extends ConfigurationSupport {
/**
* Standard Data Source
*
* @return jndiObjectFactoryBean
*/
@Bean(scope = DefaultScopes.SINGLETON)
public DataSource dataSource() {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiName("java:comp/env/jdbc/myDB");
jndiObjectFactoryBean.setProxyInterface(javax.sql.DataSource.class);
return (DataSource) this.getObject(jndiObjectFactoryBean);
}
/**
* Entity Manager
*
* @return entityManagerFactory
*/
@Bean(scope = DefaultScopes.SINGLETON)
public EntityManagerFactory entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
entityManagerFactoryBean.setDataSource(dataSource());
HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setDatabasePlatform(databaseDialect);
jpaVendorAdapter.setShowSql(true);
jpaVendorAdapter.setGenerateDdl(true);
entityManagerFactoryBean.setJpaVendorAdapter(jpaVendorAdapter);
return (EntityManagerFactory) this.getObject(entityManagerFactoryBean);
}
/**
* Transaction Manager
*
* @return transactionManager
*/
@Bean(scope = DefaultScopes.SINGLETON)
public JpaTransactionManager transactionManager() {
JpaTransactionManager transactionManager = new JpaTransactionManager();
transactionManager.setEntityManagerFactory(entityManagerFactory());
transactionManager.setDataSource(dataSource());
return transactionManager;
}
/**
* JDBC Template
*
* @return jdbcTemplate
*/
@Bean(scope = DefaultScopes.SINGLETON)
public MyJdbcTemplate jdbcTemplate() {
MyJdbcTemplate jdbcTemplate = new MyJdbcTemplate();
jdbcTemplate.setDataSource(dataSource());
return jdbcTemplate;
}
/**
* Hibernate Session Factory
*
* @return transactionManager
*/
@Bean(scope = DefaultScopes.SINGLETON)
public AnnotationSessionFactoryBean sessionFactory() {
AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
Properties hibernateProperties = new Properties();
hibernateProperties.put("hibernate.dialect", databaseDialect);
hibernateProperties.put("hibernate.autocommit", false);
sessionFactory.setHibernateProperties(hibernateProperties);
sessionFactory.setDataSource(dataSource());
Class[] annotatedClasses = {
com.project.core.model.User.class,
com.project.core.model.UserGroup.class,
com.project.core.model.Component.class,
com.project.core.model.ComponentGroup.class,
com.project.core.model.Context.class,
com.project.core.model.ContextUserRule.class,
com.project.core.model.Host.class,
com.project.core.model.UnixGroup.class
};
sessionFactory.setAnnotatedClasses(annotatedClasses);
return sessionFactory;
}
private static String databaseDialect = "org.hibernate.dialect.PostgreSQLDialect";
}
Thanks,
Mike