Quantcast
Channel: Spring Community Forums - EJB
Viewing all articles
Browse latest Browse all 7

The chosen transaction strategy requires access to the JTA TransactionManager

$
0
0
package com.evnit.fmis
Entity
Code:

@Entity
@Table(name = "sec_group", schema = "dbo", uniqueConstraints = @UniqueConstraint(columnNames = "grp_shortdescription"))
public class SecGroup implements java.io.Serializable {
        private static final long serialVersionUID = 1L;
        private Long grpId;
        private String grpShortdescription;
        private String grpLongdescription;
        private Integer version;
        public SecGroup() {
        }
        public SecGroup(Long grpId, String grpShortdescription,
                        String grpLongdescription, Integer version) {
                this.grpId = grpId;
                this.grpShortdescription = grpShortdescription;
                this.grpLongdescription = grpLongdescription;
                this.version = version;
        }
        @Id
        @Column(name = "grp_id", unique = true, nullable = false)
        public Long getGrpId() {
                return this.grpId;
        }
        public void setGrpId(Long grpId) {
                this.grpId = grpId;
        }
        ......

}

Dao
Code:

@Repository("secGroupDao")
public class SecGroupDao {
        @PersistenceContext(unitName = "fmis2")
        private EntityManager em;
        public List<SecGroup> getAllSecGroupDao() {
                String query = "SELECT dm FROM SecGroup dm";
                return em.createQuery(query).getResultList();
        }
}

Services

Code:

@Service("secGroupServices")
public class SecGroupServiceImpl implements SecGroupServices {
        @Autowired
        private SecGroupDao secGroupDao;
        @Override
        public List<SecGroup> getAllSecGroup() {
                return secGroupDao.getAllSecGroupDao();
        }

}

persistence.xml
Code:

<persistence-unit name="fmis2" transaction-type="JTA">
                <provider>org.hibernate.ejb.HibernatePersistence</provider> <!-- <class>org.zkoss.bind.examples.spring.order.domain.Order</class> -->
                <properties>
                        <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
                        <property name="hibernate.show_sql" value="true" />
                        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
                        <property name="hibernate.connection.url"
                                value="jdbc:sqlserver://localhost:1433;databaseName=sample" />
                        <property name="hibernate.connection.driver_class"
                                value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
                        <property name="hibernate.connection.username" value="sa" />
                        <property name="hibernate.connection.password" value="sa" />
                </properties>
        </persistence-unit>

applicationContext.xml
Code:

<context:annotation-config />
        <context:component-scan base-package="com.evnit.fmis" />

        <tx:annotation-driven transaction-manager="transactionManager" />
        <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                autowire="constructor">
                <property name="entityManagerFactory" ref="emf" />
        </bean>
        <bean id="emf"
                class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
                <property name="persistenceUnitName" value="fmis2" />
        </bean>

viewmodel

Code:

public class OrderVM {
        @WireVariable
        private SecGroupServices secGroupServices;
        public List<SecGroup> getOrders() {
                List<SecGroup> list = secGroupServices.getAllSecGroup();
                return list ;
        }
}

Start server Tomcat Error

Code:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'secGroupDao': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: fmis2] Unable to build EntityManagerFactory
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:342)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: fmis2] Unable to build EntityManagerFactory
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.orm.jpa.EntityManagerFactoryUtils.findEntityManagerFactory(EntityManagerFactoryUtils.java:99)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findNamedEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:511)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findEntityManagerFactory(PersistenceAnnotationBeanPostProcessor.java:493)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.resolveEntityManager(PersistenceAnnotationBeanPostProcessor.java:657)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor$PersistenceElement.getResourceToInject(PersistenceAnnotationBeanPostProcessor.java:630)
        at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:150)
        at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
        at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:339)
        ... 23 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: fmis2] Unable to build EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
        at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:92)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
        ... 37 more
Caused by: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
        at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:329)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1291)
        at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
        ... 43 more


Viewing all articles
Browse latest Browse all 7

Trending Articles