My App is built on Spring 3.0.5 and deployed in JBoss 5.1.
My DAOs are working fine for any get or getAll operations on any of the tables but any inserts or updates does nothing. I do not see any exceptions in the JBoss logs either but I do see the below line when I enable debug on JBoss. Can you please tell me what I am missing?
I suppose my DAO is unable to create or reference a transaction for the save(object) operation which I have annotated as REQUIRES_NEW.
Here's my spring-jpa.xmlCode:17:10:01,505 DEBUG [AbstractEntityManagerImpl] Looking for a JTA transaction to join 17:10:01,520 DEBUG [AbstractEntityManagerImpl] No JTA transaction found
My persistence.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- JPAAccountDAO has JPA annotations to access EntityManager --> <context:annotation-config/> <jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/ties-2EntityManagerFactory"> </jee:jndi-lookup> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManagerName" value="java:/TransactionManager"/> <property name="userTransactionName" value="UserTransaction"/> </bean> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /> <!-- Database LOB Handling --> <bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" /> <!-- Read in DAOs from the JPA package --> <context:component-scan base-package="com.rtd.ties2.dao" /> </beans>
My DAO codeCode:<persistence-unit name="ties-2" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/ties-2Datasource</jta-data-source> <!-- The <jar-file> element is necessary if you put the persistence.xml in the WAR and the classes in the JAR --> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> <!-- <property name="hibernate.hbm2ddl.auto" value="validate"/>--> <!-- <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>--> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/ties-2EntityManagerFactory"/> </properties> </persistence-unit> </persistence>
Code:package com.rtd.ties2.dao; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import com.rtddenver.gwt.client.entity.TiesVoteScheduleEntries; @Repository("tiesVoteScheduleEntriesDaoJpa") public class TiesVoteScheduleEntriesDaoJpa extends GenericDaoJpa<TiesVoteScheduleEntries> implements TiesVoteScheduleEntriesDao { private static final Log log = LogFactory.getLog(TiesVotesDaoJpa.class); public TiesVoteScheduleEntriesDaoJpa(){ super(TiesVoteScheduleEntries.class); } @PersistenceContext protected EntityManager entityManager; public void setEntityManager(EntityManager entityManager){ this.entityManager = entityManager; } @Transactional(propagation = Propagation.REQUIRES_NEW) public void save(TiesVoteScheduleEntries object) { log.debug("persisting TiesVoteScheduleEntries instance"); try { entityManager.persist(object); log.info("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } catch (Exception e) { log.error("persist failed", e); e.printStackTrace(); } } }Code:public class GenericDaoJpa<T extends DomainObject> implements GenericDao<T> { private Class<T> type; private static final Log log = LogFactory.getLog("GenericDaoJpa"); @PersistenceContext protected EntityManager entityManager; public void setEntityManager(EntityManager entityManager){ this.entityManager = entityManager; } public GenericDaoJpa(Class<T> type){ super(); this.type = type; } @Override //@Transactional(readOnly=true) public T get(BigDecimal id) { log.debug("getting instance with id: " + id); if (id == null){ return null; } else{ try { return entityManager.find(type, id); } catch (RuntimeException re) { log.error("get failed", re); throw re; } } } @Override //@Transactional(readOnly=true) public T get(int id) { log.debug("getting instance with id: " + id); if (id == 0){ return null; } else{ try { return entityManager.find(type, id); } catch (RuntimeException re) { log.error("get failed", re); throw re; } } } @Override //@Transactional(readOnly=true) public List<T> getAll() { return entityManager.createQuery("select o from " + type.getName() + " o").getResultList(); } @Override //@Transactional(propagation = Propagation.REQUIRES_NEW) public void save(T object) { log.debug("persisting TiesEmployees instance"); try { entityManager.persist(object); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } } @Override public void delete(T object) { entityManager.remove(object); } @Override public T merge(T object) { log.debug("merging instance"); try { return entityManager.merge(object); } catch (RuntimeException re) { log.error("merge failed", re); throw re; } } }


Reply With Quote
