Unit test with hibernate

13 views
Skip to first unread message

Hao Chen

unread,
Jun 24, 2015, 1:03:23 PM6/24/15
to thread...@googlegroups.com
Hi guys, 
I am a newbie to thread weaver. Hope i can get some help from here.
The question is regarding writing some multithread unit tests for my hibernate based api. I was using HSQL (in mem database) as the way i tested for hibernate. It worked perfect until i wanted to write some mulithread unitests.

I tried to do some setup in @ThreadedBefore 
AnnotationSessionFactoryBean factoryBean = new AnnotationSessionFactoryBean();
factoryBean.setHibernateProperties(getTestConfig());
String[] packagesToScan = {"com.blablab"};
factoryBean.setPackagesToScan(packagesToScan);
factoryBean.afterPropertiesSet();
sessionFactory = (SessionFactory) factoryBean.getObject();

It failed with errors,

Caused by: java.lang.NullPointerException
at com.google.testing.instrumentation.InstrumentedClassLoader.loadClassData(InstrumentedClassLoader.java:152)
at com.google.testing.instrumentation.InstrumentedClassLoader.findClass(InstrumentedClassLoader.java:137)
at com.google.testing.instrumentation.InstrumentedClassLoader.loadClass(InstrumentedClassLoader.java:113)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:170)
at org.hibernate.cfg.Configuration.applyHibernateValidatorLegacyConstraintsOnDDL(Configuration.java:1663)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1653)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1445)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at com.repository.TestSessionHelper.getSessionFactory(TestSessionHelper.java:20)


I aslo posted some code in 


Any help would be appreciated.
Thanks,
Hao

Alasdair Mackintosh

unread,
Jun 24, 2015, 1:41:45 PM6/24/15
to thread...@googlegroups.com
Answered on stackoverflow.
Reply all
Reply to author
Forward
0 new messages