Results 1 to 8 of 8

Thread: AbstractJpaTests does not roll back transaction

  1. #1
    Join Date
    Dec 2005
    Location
    California
    Posts
    63

    Default AbstractJpaTests does not roll back transaction

    Hi
    I am using AbstractJpaTests, the test passes successfully, however, after it finishes, I look into the database and the test record is still there. My application.xml looks like this:
    Code:
    <bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/dac" />
    		<property name="username" value="dacUser" />
    		<property name="password" value="dacUser" />
    	</bean>
    
    	<!-- JPA EntityManagerFactory -->
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="dataSource" ref="dataSource"/>
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    			    <property name="databasePlatform"
    						value="org.hibernate.dialect.MySQL5Dialect"/>
    				<property name="generateDdl" value="true"/>
    				<property name="showSql" value="true" />
    			</bean>
    		</property>
    		
    	</bean>
    
    	<!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory"/>
    		<property name="dataSource" ref="dataSource"/>
    	</bean>
    
    
    	<!--
    		Instruct Spring to perform declarative transaction management automatically
    		on annotated classes.
    	-->
    	<tx:annotation-driven/>
    
    	<!--
    		PostProcessors to perform resource injection according to the JPA specification
    	  (@PersistenceContext, @PersistenceUnit).
    	-->
    	<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
    
    	<!--
    		PostProcessors to perform exception translation on @Repository classes (from native
    		exceptions such as JPA PersistenceExceptions to Spring's DataAccessException hierarchy).
    	-->
    	<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
    
        <bean id="clinicDao" class="org.springframework.samples.petclinic.jpa.JpaTemplateClinic">
              <property name="entityManagerFactory" ref="entityManagerFactory"/>
      </bean>
    My test looks like this:
    Code:
    public class ClinicIntegrationTest extends AbstractJpaTests {
    
    	protected JpaTemplateClinic jpaTemplateClinic;
    	
    	protected String[] getConfigLocations(){
            return new String[] {"classpath:/applicationContext.xml"};
    	}
    	
    	public void testInserts() throws Exception { 
    		Manvita m = new Manvita();
    		m.setName("paruchuri");
    		jpaTemplateClinic.storeAny(m);
    		Collection<Manvita> manvitas = jpaTemplateClinic.findManvitas();
    		assertEquals("Wrong number", 1, manvitas.size());
    	}
    
    	public void setClinicDao(JpaTemplateClinic jpaTemplateClinic) {
    		this.jpaTemplateClinic = jpaTemplateClinic;
    	}
    }
    The JpaTemplateClinic has no annotations, the persistent class Manvita uses annotations.
    Janos

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you want it to be transactional don't have have to set it up to use InnoDB.

  3. #3
    Join Date
    Dec 2005
    Location
    California
    Posts
    63

    Default it worked

    Thanks, when I created a table with the InnoDB engine, it worked:

    Code:
    create table manvita(id int AUTO_INCREMENT PRIMARY KEY, 
                                 name varchar(255)) 
                                 ENGINE=InnoDB
    Janos

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Not a problem, glad it worked! I've started using MySQL myself recently and fell into this trap last week. It's come up on the forum before which is why I didn't spend too long wondering what I was doing wrong .

  5. #5
    Join Date
    Mar 2007
    Posts
    125

    Default

    hi, could you provide a "template application"? i mean - just a configuration, with list o libraries to use.

    i've been trying to create spring+jpa applications for almost two weeks.

    i've almost managed to complete this using toplink but there were problems with transactions... now i'm trying hibernate's jpa and i have weird exceptions and the applications doesn't run


    ps. do you have your application in some directory with spaces? (i have in "Program Files/some_more_path..." and i'm curious if that might be my problem)

    cheers!

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you have a new problem, it makes sense to post a new thread. There was an article about this on the interface21 team blog a while about, it might be useful. If you google I'm sure you'll find lots of JPA examples. It's also a good idea to post the information related to the problem if you want help.
    http://blog.interface21.com/main/200...-in-spring-20/

  7. #7
    Join Date
    Mar 2007
    Posts
    125

    Default

    hi karldmoore,

    i've already made one topic (jpa+toplink) with my problems - unfortunatelly only one person replied with some advices, but the problem was not solved so i was thinking about migrating to jpa+hibernate.

    i think i've google almost every example there is
    i also saw the one you are referring me to. i've already tried that (despite that author uses testing example with simpleloadtimeweaver instead of normal one, and uses no transactional/persistencecontext annotations) and tried many more - spring+jpa simple doesn't like me i guess :-)

    but i'll give a try and make new topic, this time with hibernate as a jpa vendor.

    cheers!

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Ok, when you've reposted it I'll take a look. It just makes it easier to track threads when you post different problems in their own thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •