jady0
jady0
2011-01-22 15:46

hibernate未初始化

  • hibernate

package com.jady.test;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import com.jady.domain.Dept;
import com.jady.domain.Emp;
import com.jady.domain.HibernateSessionFactory;

public class TestEmpDept {

@Test
public void test(){
    Session session = null;
    Transaction tx = null;

    try {
        session = HibernateSessionFactory.getSession();
        tx = session.beginTransaction();

        Dept dept = new Dept();
        dept.setName("财务");

        Emp e1 = new Emp();
        e1.setName("tom");
        Emp e2 = new Emp();
        e2.setName("jerry");            

//

//

// //关系
e1.setDept(dept);
e2.setDept(dept);
//

Set emps = new HashSet();
emps.add(e1);
emps.add(e2);
//

dept.setEmps(emps);
//

// //保存
// session.save(dept);
// session.save(e1);
// session.save(e2);

        tx.commit();
    } catch (HibernateException e) {
        e.printStackTrace();
        tx.rollback();
    }finally{
        HibernateSessionFactory.closeSession();
    }



}

}

HibernateSessionFactory是用MyEclipse自动添加的,运行报错如下:

java.lang.NoClassDefFoundError: Could not initialize class com.jady.domain.HibernateSessionFactory
at com.jady.test.TestEmpDept.test(TestEmpDept.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

INFO Environment:514 - Hibernate 3.2.5
INFO Environment:547 - hibernate.properties not found
INFO Environment:681 - Bytecode provider name : cglib
INFO Environment:598 - using JDK 1.4 java.sql.Timestamp handling
INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
INFO Configuration:553 - Reading mappings from resource : com/jady/domain/Emp.hbm.xml
INFO HbmBinder:300 - Mapping class: com.jady.domain.Emp -> Emp
INFO Configuration:553 - Reading mappings from resource : com/jady/domain/Dept.hbm.xml
INFO HbmBinder:300 - Mapping class: com.Jady.domain.Dept -> Dept

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

6条回答

为你推荐

换一换