集成Hibernate配置

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/oa</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>   
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"></property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <mapping resource="com/bjsxt/oa/model/ACL.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/ApproveInfo.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/Document.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/Module.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/Organization.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/Person.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/Role.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/User.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/UsersRoles.hbm.xml"/>
    <mapping resource="com/bjsxt/oa/model/Workflow.hbm.xml"/>
  </session-factory>
</hibernate-configuration>






********************************************************************************************


public static void main(String[] args) {
   
            try {
                config = new Configuration().configure(new File(
                        "src/hibernate.cfg.xml"));

                System.out.println("Creating tables...");

                SessionFactory sessionFactory = config.buildSessionFactory();
                session = sessionFactory.openSession();
                tx = session.beginTransaction();

                SchemaExport schemaExport = new SchemaExport(config);
                schemaExport.create(true, true);
//                BasicCorp bc = new BasicCorp();
//                bc.setBasicCorpAddress("jerryhan");
//                bc.setBasicCorpName("特种不对");
//                session.save(bc);
                System.out.println("Table created.");
               
                tx.commit();

            } catch (HibernateException e) {
                e.printStackTrace();
                try {
                    tx.rollback();
                } catch (HibernateException e1){
                    e1.printStackTrace();
                }
            } finally {
                session.close();

            }


          

}   

你可能感兴趣的:(集成Hibernate配置)