开发者

junit hibernate netbeans: CurrentSessionContext

I'm trying to test my hibernate project with junit tests and I keep on getting org.hibernate.HibernateException: No CurrentSessionContext configured!

I can manually run the hibernate requests and they work fine (i.e. I have included <property name="hibernate.current_session_context_class">thread</property> which seems the be the regular cause of the aforementioned exception).

It seems as if the j开发者_开发百科unit test does not 'pick up' the hibernate.cfg.xml file because it's lying in the default Netbeans Test Packages folder.


Make sure that the hibernate.xml.cfg file is in the same directory as the junit test class. By default it will look for the file in the same directory it I executed in, unless the path is specified in the sessionfactory object when created.

Update: Also make sure that you initialize the sessionFactory. When you get a new session, it is possible that you've never initialized the factory, since your unit test could be bypassing the code that generally initializes it.

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜