TestNG with EntityHome
quaidbrown Jul 1, 2008 7:13 PMDoes anybody have an example that shows a TestNG test successfully using an EntityHome object to persist?
I'm having a hard time making it work, and I'm sure it's due to my ephemeral understanding of how injection and PersistenceContext and EntityManagers and the like works behind the scenes.
My latest error is:
[Parser] Running:
/root/workspace/projName-test/temp-testng-customsuite.xml
WARN [org.jboss.seam.init.Initialization] Did not install PojoCache due to NoClassDefFoundError: org/jgroups/MembershipListener
WARN [org.jboss.seam.Component] Component class should be serializable: AnomalySet
INFO [org.ajax4jsf.cache.CacheManager] Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
INFO [org.ajax4jsf.cache.LRUMapCacheFactory] Creating LRUMap cache instance using parameters: {}
INFO [org.ajax4jsf.cache.LRUMapCacheFactory] Creating LRUMap cache instance of default capacity
INFO [org.ajax4jsf.cache.CacheManager] Selected [org.ajax4jsf.cache.LRUMapCacheFactory] cache factory
INFO [org.ajax4jsf.cache.LRUMapCacheFactory] Creating LRUMap cache instance using parameters: {}
INFO [org.ajax4jsf.cache.LRUMapCacheFactory] Creating LRUMap cache instance of default capacity
INFO [org.domain.projName.session.AnomalySetHome] AnomalySetHome.persist() action called with: Id: nullName:debugTestName
Hibernate:
select
nextval ('hibernate_sequence')
FAILED: testThisThing
javax.persistence.TransactionRequiredException: no transaction is in progress
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:294)
at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90)
at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.flush(FullTextEntityManagerImpl.java:102)
at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90)
at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:85)
at org.domain.projName.session.AnomalySetHome.persist(AnomalySetHome.java:72)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
at org.jboss.seam.util.Work.workInTransaction(Work.java:41)
at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
at org.domain.projName.session.AnomalySetHome_$$_javassist_0.persist(AnomalySetHome_$$_javassist_0.java)
at org.domain.projName.test.AnomalySetTest$1.testComponents(AnomalySetTest.java:231)
at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:169)
at org.domain.projName.test.AnomalySetTest.testThisThing(AnomalySetTest.java:236)
... Removed 26 stack frames
And it happens with this code:
new ComponentTest(){
@Override
protected void testComponents() throws Exception{
SampleSetHome sampleSetHome = (SampleSetHome)Component.getInstance("SampleSetHome", true);
SampleSet curSampleSet = new SampleSet();
sampleSetHome.setInstance(curSampleSet);
//Commented out code from previous attempts and errors:
//EntityManager em = emfProd.createEntityManager();
//setField(sampleSetHome, "entityManager", em)
//Log sampleSetHomeLog = Logging.getLog(Log.class);
//setField(sampleSetHome, "log", sampleSetHomeLog);
anomalySetHome.persist();
}
}.run();Anyway, any advice is appreciated.