<hibernate-mapping package=\"com.test.pojo\">
<class name=\"User\" table=\"users\" >
<id name=\"usersId\" type=\"long\">
<column name=\"usersId\"></column>
<generator class=\"increment\"></generator>
</id>
<property name=\"usersName\" type=\"string\">
<column name=\"usersName\"></column>
</property>
<property name=\"usersPw\" type=\"string\">
<column name=\"usersPw\"></column>
</property>
</class>
</hibernate-mapping>
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtils {
private static SessionFactory factory;
static {
try {
Configuration cfg = new Configuration().configure();
factory = cfg.buildSessionFactory();
}catch(Exception e) {
e.printStackTrace();
}
}
public static SessionFactory getSessionFactory() {
return factory;
}
public static Session getSession() {
return factory.openSession();
}
public static void closeSession(Session session) {
if (session != null) {
if (session.isOpen()) {
session.close();
}
}
}
}
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class ExportDB {
public static void main(String[] args) {
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
}
}
\"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name=\"connection.driver_class\">com.mysql.jdbc.Driver</property>
<property name=\"connection.url\">jdbc:mysql://localhost:3306/b2c2</property>
<property name=\"dialect\">org.hibernate.dialect.MySQLDialect</property>
<property name=\"myeclipse.connection.profile\">mysql</property>
<property name=\"connection.username\">root</property>
<property name=\"connection.password\">root</property>
<property name=\"show_sql\">true</property>
<mapping resource=\"com/test/pojo/Privilege.hbm.xml\" />
<mapping resource=\"com/test/pojo/Role.hbm.xml\" />
<mapping resource=\"com/test/pojo/User.hbm.xml\" />
</session-factory>
</hibernate-configuration>
















