java 求助!-------------急!!!【已解决】
我用hibernate连接数据库,数据访问对象为:public class DAORootAB{private Session session;
/**
* DAO构造器
*/
public DAORootAB() {
createSession();
}
public void createSession() {
// TODO 创建会话
System.out.println("---");
if (this.session == null) {
Configuration config = new AnnotationConfiguration().configure();
SessionFactory factory = config.buildSessionFactory();
this.session = factory.openSession();
}
}
... 其他略
当我使用线程访问是,却无法加载这个类,跟踪程序到Configuration config = new AnnotationConfiguration().configure(); 这一行就在中断。
简单的线程如下:public class WorkThread implements Runnable{
@Override
public void run(){
DAORootAB dao = new DAORootAB();
}
}测试代码(Junit4.4),喜欢用 main测试的代码也是一样:public class MailRunnerTC {
@Test
public void testname() throws Exception {
new Thread(new WorkThread()).start();
}hibernate配置文件略了。。。。急!!!!
后院各位帮帮忙
[ 本帖最后由 xinggg22 于 2008-5-17 12:42 编辑 ] 不知有没有解决。。。。帮顶了下。。。 Configuration config = new AnnotationConfiguration().configure();
建议这里分开来.
试下这样.
cfg = new Configuration();
sessionFactory =cfg.configure().buildSessionFactory();
[ 本帖最后由 hjack 于 2008-5-16 22:59 编辑 ] 回楼上~~你的方法 之前试过,没用。。。。
还没解决。顶!因为我放弃了原来的做法,所以,没有解决,继续求救。。 其实有没有错误代码,错误日志???? 发log出来睇睇~~ 实在抱歉。。原因是,因为在Junit在测试多线程存在问题。线程自身会启动失败。
解决办法:1.实用JUnit的扩张类GroboUtils 。2.是用JUnit的TestRunner。3.直接用main来做测试。
在可能出现异常的地方都基本会记录下来,log文件是没有出现任何异常或者错误的,因为是线程本身没有启动的问题。所以就不贴出来了。
页:
[1]