开发者

junit hibernate netbeans: CurrentSessionContext

开发者 https://www.devze.com 2023-04-05 02:46 出处:网络
I\'m trying to test my hibernate project with junit tests and I keep on getting org.hibernate.HibernateException: No CurrentSessionContext configured!

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

精彩评论

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