hibernate.cfg.xml配置文件
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="hbm2ddl.auto">update</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.url">jdbc:mysql://192.168.1.213:3306/cclj</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">localhost-MySql</property>
<property name="format_sql">true</property>
<!--采用annotation方式-->
<mapping class="com.relonger.cclj.bean.Car" />
<mapping class="com.relonger.cclj.bean.Message" />
</session-factory>
</hibernate-configuration>
测试代码写法
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;
public class CreateTable {
@Test
public void testUnidirectionalMany_To_One(){
//Configuration cf=new Configuration().configure();//配置文件方式
AnnotationConfiguration cf = new AnnotationConfiguration().configure();//注解方式
SchemaExport ct=new SchemaExport(cf);
ct.create(true, true);
}
}