Configuration of Hibernate environment
Configuration of the Hibernate.cfg.xml
<?XML version= ' 1.0 ' encoding= ' utf-8 '?><!DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://www.hi Bernate.org/dtd/hibernate-configuration-3.0.dtd "><hibernate-configuration> <session-factory> <!--Database Connection Settings - < Propertyname= "Connection.driver_class">Oracle.jdbc.driver.OracleDriver</ Property> < Propertyname= "Connection.url">Jdbc:oracle:thin:@127.0.0.1:1521:orcl</ Property> < Propertyname= "Connection.username">Scott</ Property> < Propertyname= "Connection.password">Tiger</ Property> <!--JDBC Connection pool (use the built-in) - <!--<property name= "connection.pool_size" >10</property> - <!--minimum number of connections for database connections - < Propertyname= "C3p0.min_size">10</ Property> <!--maximum number of connections to a database connection - < Propertyname= "C3p0.max_size">100</ Property> < Propertyname= "C3p0.timeout">3000</ Property> < Propertyname= "Hibernate.temp.use_jdbc_metadata_defaults">False</ Property> <!--SQL dialect dialect - < Propertyname= "dialect">Org.hibernate.dialect.Oracle10gDialect</ Property> <!--Echo all executed SQL to stdout (console) - < Propertyname= "Show_sql">True</ Property> <!--formatted SQL statement output view - < Propertyname= "Format_sql">True</ Property> <!--Drop and re-create the database schema on startup - < Propertyname= "Hbm2ddl.auto">Update</ Property> <!--mapping files for entity classes - <MappingResource= "Com/zhiyou/entity/user.hbm.xml"/> </session-factory></hibernate-configuration>
View Code
Each entity class corresponds to a mapping file
such as the user class, with the Username,password,role property
corresponding mapping file User.hbm.xml
<?XML version= "1.0"?><!DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "Http://www.hibernate.org/dtd/hibe Rnate-mapping-3.0.dtd "><hibernate-mapping Package= "Com.zhiyou.entity"> <!--class: Specifies the entity class name: Entity class names Table: Name of the tables in the database - <classname= "User"Table= "User1"> <!--ID PRIMARY Key - <IDname= "Name"column= "user_name"> <!--primary key Generation policy assigned: The user specifies the primary key sequence: Specifies the sequence UUID of the Oracle database: produces a 32-bit string Nati VE: Automatic selection of primary key generation strategy based on database - <!--<generator class= "sequence" > Parameter name <param name= "sequence" >seq_test</param> </generator> - <Generatorclass= "Native"></Generator> </ID> < Propertyname= "pwd"column= "Password"/> < Propertyname= "Role"column= "Role"/> </class></hibernate-mapping>
View Code
It is important to note that the mapping file for the entity class needs to be configured in Hibernate.cfg.xml.
One-to-many
Hibernate, one-to-many, many-to-a