-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: JPA/Hibernate/Spring commit issue run from my test
PostPosted: Sun Dec 26, 2010 2:40 pm 
Newbie

Joined: Sun Dec 26, 2010 2:37 pm
Posts: 2
Hi, I'm having this same issue for some time so I think it's time to reach out to those more informed about what the problem could be. The main issue that I'm having is that my test is failing because my JPA/Hibernate transaction is not being committed to my in memory HSQLDB. No other relevant errors are being thrown, and I don't believe that I have to do a EntityManager.flush to make this transaction commit, however, when I do add in this em.flush, i get another error. Here is my hibernate.properties, persistence.xml, applicationContextTest.xml, test class, and stack trace. Really stuck on this and would highly appreciate any input anyone has to help me understand why my code is not persisting the data from my test. Hopefully someone will respond and I can post my entire console output which is quite long. Thank you very very very much for anything you can do to help me.

**Hibernate.properties**

hibernate.connection.driver_class = org.hsqldb.jdbcDriver
hibernate.connection.url = jdbc:hsqldb:mem:staffing;shutdown=true;hsqldb.write_delay=false;
hibernate.connection.username = sa
hibernate.connection.password =
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.HSQLDialect

hibernate.show_sql=true
hibernate.format_sql=true
hibernate.default_batch_fetch_size=5
hibernate.generate_statistics=false
hibernate.use_sql_comments=true
hibernate.jdbc.batch_size=10

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=true
hibernate.cache.provider_class=net.sf.ehcache.hibernate.EhCacheProvider
hibernate.cache.use_structured_entries=true

hibernate.hbm2ddl.auto=create-drop




**My persistence.xml**

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

<persistence-unit name="staffingPersistenceUnit" transaction-type="RESOURCE_LOCAL">

<class>com.snrstaffing.model.Client</class>
<class>com.snrstaffing.model.Candidate</class>
<class>com.snrstaffing.model.ClientCandidate</class>

</persistence-unit>
</persistence>




**my applicationContextTest.xml file that gets read in from my Test**

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/b ... ns-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/a ... op-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/c ... xt-2.5.xsd"
default-autowire="byName">

<!--<context:component-scan base-package="*" /> -->

<!--<bean id="writer" class="com.snrstaffing.service.Writer" />-->

<!--<bean id="mySpringBeanWithDependency" class="com.snrstaffing.service.MySpringBeanWithDependency">-->
<!--<property name="writer" ref="writer" />-->
<!--</bean>-->


<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:staffing"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="staffingPersistenceUnit" />
<property name="jpaVendorAdapter">

<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

<property name="showSql" value="true"/>

<property name="generateDdl" value="true"/>

</bean>

</property>
</bean>


<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">

<property name="entityManagerFactory" ref="entityManagerFactory"/>

<property name="dataSource" ref="dataSource"/>

</bean>


<!--<tx:annotation-driven transaction-manager="transactionManager" />-->

<!--<tx:annotation-driven />-->

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>


<bean id="genericDao" class="com.snrstaffing.model.dao.jpa.GenericJpaDao">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<bean id="abstractPersistentEntity" class="com.snrstaffing.model.common.AbstractPersistentEntity" abstract="true">
<property name="genericDao" ref="genericDao"/>
</bean>

<bean id="client" class="com.snrstaffing.model.Client" parent="abstractPersistentEntity"/>

</beans>



** My Test Class **

package com.snrstaffing.model;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;

import java.util.List;

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;

/**
* Created by IntelliJ IDEA.
* User: Dan
* Date: Dec 11, 2010
* Time: 12:34:46 AM
* To change this template use File | Settings | File Templates.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/applicationContextTest.xml"})
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
public class ClientTest {
@Before
public void setUp() throws Exception {
//add a bunch of records
Client client = new Client();
client.setFirstName("Jane");
client.setLastName("Doe");
client.persist();
}

@After
public void tearDown() throws Exception {
}

@Test
public void dumbTest() {
List<Client> allClients = Client.findAll(Client.class);
assertNotNull("allClients was null", allClients);
assertTrue("allClients size was supposed to be 1", allClients.size() > 0);
}
}

** The Stack Trace **


junit.framework.AssertionFailedError: allClients size was supposed to be 1
at com.snrstaffing.model.ClientTest.dumbTest(ClientTest.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:94)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:165)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:110)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.