本文主要是介绍【hibernate4.3】slf4j to log4j and Junit,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
slf4j to log4j
log4j 是对slf 标准的实现
配置文件
log4j.logger.org.hibernate.tool.hbm2ddl=debug
可以将DDL显示在console
Junit
在user libraries 下创建 myJunit libraries
package hibernateDemo.test;import static org.junit.Assert.*; import hibernateDemo.model.Teacher;import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.cfg.Configuration; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test;public class TeacherJunit {private static SessionFactory sf = null ;@BeforeClasspublic static void beforeClass(){sf = new AnnotationConfiguration().configure().buildSessionFactory();}@Testpublic void test() {Teacher t = new Teacher(); t.setId(28); t.setName("cc"); t.setTitle("初级"); Session session = sf.openSession(); session.beginTransaction(); session.save(t); session.getTransaction().commit(); session.close(); System.out.println("junit");}@AfterClasspublic static void afterClass(){sf.close();}}
这篇关于【hibernate4.3】slf4j to log4j and Junit的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!