How to write two configuration files of Hibernate

It should be noted that these two configuration files are generally written under src. After the mapping is completed, remember to use ctrl to check whether the mapping is successful.

The first is the .cfg.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
	
<hibernate-configuration>
    <session-factory>
        <!--Step 1: Configure database information: Get this information from the hibernate.properties file-->
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql:///mysql</property><!--Three slashes indicate that the default is the local 3306 port, fill in the database name here-->
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password">2257696</property>
        
        <!--Step 2: Configure Hibernate information (optional)-->
        <!--Output the underlying SQL statement-->
        <property name="hibernate.show_sql">true</property>
        <!--The output SQL statement has the format -->
        <property name="hibernate.format_sql">true</property>
        <!--Let hiberna automatically update/create tables-->
        <property name="hibernate.hbm2ddl.auto">update</property>
        <!--Configure the dialect of the database (note: the dialect version is incorrect and the program cannot be performed normally, here is the dialect of the MYSQL5 version)-->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
        
        <!--Step 3: Introduce the mapping file (core)-->
        <!--Note: Under src, start directly with the package name. Here you can use the ctrl key to verify whether the mapping is successful -->
        <mapping resource = "NewFile.hbm.xml"/>
    </session-factory>
</hibernate-configuration>



After that is the .hbm.xml file
<?xml version="1.0" encoding="UTF-8"?>

<!--Introduce dtd constraints-->
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    
<hibernate-mapping>
    <class name = "hiber1.User" table = "newtableTest"><!--The full path of the class written in class-->
        <id name = "uid" column = "uid">
            <generator class = "native"></generator>
        </id>
        
        <property name="username" column = "username"></property>
        <property name="password" column = "password"></property>
        <property name="address" column = "address"></property>
    </class>
</hibernate-mapping>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326036419&siteId=291194637