hibernate类⽣成表的实现源码第⼀步:
在test包中创建⼀个⽣成表的java类:
st;
import org.hibernate.cfg.Configuration;
import l.hbm2ddl.SchemaExport;
public class ⽣成表 {
/**
* @param args
*/
public static void main(String[] args) {
Configuration cfg = new Configuration().configure();
SchemaExport ex = new SchemaExport(cfg);
}
}
第⼆步:
写⼀个创建ssion的类:
st;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
临别
竞走速度public class HibernateSessionFactory {
private static Configuration cfg = new Configuration().configure();
private static SessionFactory factory = cfg.buildSessionFactory();
private static ThreadLocal<Session> local = new ThreadLocal<Session>();
public static Session getSession(){
Session ssion = (); //取
if (ssion==null || ssion.isOpen()==fal){
年的由来传说故事
ssion = factory.openSession();
local.t(ssion); //存
}
return ssion;
}
}
第三步:
修改hibernate的配置⽂件相关属性、驱动。
手机发烫
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclip Hibernate Tools. -->
<hibernate-configuration>
<ssion-factory>
<property name="tion.profile">【这⾥是什么数据库就写什么】mysql</property>
<property name="connection.url">文明礼仪画
【数据库连接是什么数据库写什么数据库test
】jdbc:mysql://localhost:3306/test
作业的重要性</property>
<property name="dialect">
【是mysql就写mysql orc就orc】org.hibernate.dialect.MySQLDialect
阿登反击战
</property>
<property name="connection.urname">root</property>
<property name="connection.password">admin</property>
<property name="connection.driver_class">
【驱动要改】sql.jdbc.Driver
奶瓶龋齿怎么治疗
</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<mapping resource="com/pojos/l" />
<mapping resource="com/pojos/l" />
</ssion-factory>
</hibernate-configuration>
第四步 改pojo映射⽂件:
<hibernate-mapping>
<class name="com.pojos.TSaleform3" table="T_SALEFORM3" schema="test">【这地⽅的schema=“数据库名字”
】