Constraints of hibernate
<?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">
orm metadata
hibernate.cfg.xml
<?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> <!-- #hibernate.dialect org.hibernate.dialect.MySQLDialect #hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect #hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect #hibernate.connection.driver_class com.mysql.jdbc.Driver #hibernate.connection.url jdbc:mysql:///test #hibernate.connection.username gavin #hibernate.connection.password --> <!-- database driver--> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <!-- database url --> <property name="hibernate.connection.url">jdbc:mysql:///hibernate_32</property> <!-- database connection username--> <property name="hibernate.connection.username">root</property> <!-- database connection password--> <property name="hibernate.connection.password">12345678</property> <!-- database dialect In different databases, the sql syntax is slightly different. Specifying the dialect allows the hibernate framework to generate the sql statement for the database's dialect. SQL99 standard: DDL definition language library table addition, deletion, modification and query DCL Control Language Transaction Permissions DML Manipulation Language CRUD Note: When choosing a dialect for MYSQL, please choose the shortest dialect. --> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- #hibernate.show_sql true #hibernate.format_sql true --> <!-- Print the sql statement generated by hibernate to the console --> <property name="hibernate.show_sql">true</property> <!-- Format the sql statement generated by hibernate (syntax indentation) --> <property name="hibernate.format_sql">true</property> <!-- ## auto schema export Automatically export table structure. Automatically create table #hibernate.hbm2ddl.auto create Automatically create a table. A new table will be created every time the framework runs. The previous table will be overwritten and the table data will be lost. (For testing in the development environment) #hibernate.hbm2ddl.auto create-drop Automatically create tables. All tables will be deleted every time the framework runs. (For testing in the development environment) #hibernate.hbm2ddl.auto update (recommended) Automatically generate a table. If it already exists, it will not be generated again. If the table changes. Automatically update the table (no data will be deleted). #hibernate.hbm2ddl.auto validate Verification. No table is automatically generated. Each startup will verify whether the table in the database is correct. The verification fails. --> <property name="hibernate.hbm2ddl.auto">update</property> <!-- Introduce orm metadata Path writing: fill in the path under src --> <mapping resource="cn/itheima/domain/Customer.hbm.xml" /> </session-factory> </hibernate-configuration>
Primary key configuration
hibernate.cfg.xml