Hi,
I'm trying to setup a project using hibernate jpa, spring, mysql and tomcat 6. I'm using hibernate jpa and a jpatransactionmanager. When I run a junit test on my dao I see the "Hibernate: insert into message (post_date, message_header, message_string) values (?, ?, ?)". But when I run the webapp hibernate does not report inserting the message. I've tried changing multiple things but nothing works. Does anyone see a mistake that I have made?
I really don't understand it since i have the <tx:annotation-driven/> declaration I would assume Spring would find the @Transactional annotations. I have tried em.flush() after the persist but then I get an error that no transaction is currently ongoing. Can anyone please help me?
I've done the following configuration:
Code:<context:property-placeholder location="classpath*:META-INF/*.properties"/> <context:component-scan base-package="be.tim.fest"/> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${database.driverClassName}"/> <property name="url" value="${database.url}"/> <property name="username" value="${database.username}"/> <property name="password" value="${database.password}"/> <property name="initialSize" value="1"/> <property name="maxActive" value="5"/> </bean> <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/> <property name="packagesToScan" value="be.tim.fest"/> </bean> <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> <property name="database" value="MYSQL"/> <property name="showSql" value="true"/> <property name="generateDdl" value="false"/> <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect"/> </bean> <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="dataSource" ref="dataSource"/> <property name="entityManagerFactory" ref="emf"/> </bean> <tx:annotation-driven/>Code:@Service("messageService") @Transactional(readOnly = true, propagation = Propagation.REQUIRED) public class MessageServiceImp implements MessageService{ @Inject private MessageDao messageDao; public List<Message> getAllMessages() { return messageDao.getAllMessages(); } @Transactional(readOnly = false) public void addMessage(Message m) { messageDao.addMessage(m); } }Thanks in advance!Code:@Repository("messageDao") public class MessageDaoJpa implements MessageDao{ private static final Logger logger = Logger.getLogger(MessageDaoJpa.class); @PersistenceContext private EntityManager em; public void addMessage(Message m) { em.persist(m); logger.info("Insert new message: " + m.toString()); //em.flush(); } public List<Message> getAllMessages() { return em.createQuery("select m from Message m", Message.class).getResultList(); } }


Reply With Quote
