像之前基于映射文件 .hbm.xml 的SessionFactory类的写法是这样的
<span style="font-size:18px;color:#33CC00;">private static SessionFactory sessionFactory ; static { sessionFactory = new Configuration().configure().buildSessionFactory(); }</span>
<span style="font-size:18px;color:#FF0000;">SchemaExport schemaExport = new SchemaExport(new Configuration().configure()); schemaExport.create(true,true);</span>
<span style="background-color: rgb(51, 255, 51);"><span style="font-size:18px;">static { sessionFactory = new AnnotationConfiguration().configure().addPackage("com.test.hibernate").addAnnotatedClass(Car.class).buildSessionFactory(); }</span></span>
<span style="background-color: rgb(51, 255, 51);"><span style="font-size:18px;">SchemaExport schemaExport =new SchemaExport(new AnnotationConfiguration().configure().addPackage("com.test.hibernate").addAnnotatedClass(Car.class)); schemaExport.create(true,false);</span></span>
Hibernate 基于注解的SessionFactory类的生成以及自动生成表SchemaExport类的
原文地址:http://blog.csdn.net/u013803262/article/details/44727531