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> < Propertyname= "Connection.username">Root</ Property> < Propertyname= "Connection.password">Xxx</ Property> < Propertyname= "Connection.driver_class">Com.mysql.jdbc.Driver</ Property> < Propertyname= "Connection.url">Jdbc:mysql://localhost:3306/hibernate_demo</ Property><!--Select Database dialect - < Propertyname= "dialect">Org.hibernate.dialect.MySQLDialect</ Property><!--whether to output SQL statements in the console - < Propertyname= "Show_sql">True</ Property> < Propertyname= "Format_sql">True</ Property><!--Update for updating database tables, common create: If the database exists, the table is first removed and rebuilt - < Propertyname= "Hbm2ddl.auto">Update</ Property> <MappingResource= "Students.hbm.xml" /> </session-factory></hibernate-configuration>
Students.hbm.xml
<?XML version= "1.0"?><!DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd "><!--Generated 2017-7-10 22:35:01 by Hibernate Tools 3.5.0.Final -<hibernate-mapping><!--class name is Package.classname - <classname= "Xml_onetomany." Students "Table= "STUDENTS"> <IDname= "Sid"type= "int"> <columnname= "SID" /><!--assigned: When initializing the object, the SID should be assigned manually, otherwise int defaults to 0, other type error; Native: automatic growth, different meanings for different databases - <Generatorclass= "Assigned" /> </ID> < Propertyname= "Name"type= "Java.lang.String"> <columnname= "NAME" /> </ Property> < Propertyname= "Gender"type= "Java.lang.String"> <columnname= "GENDER" /> </ Property> < Propertyname= "Address"type= "Java.lang.String"> <columnname= "ADDRESS" /> </ Property> </class></hibernate-mapping>
Hibernate.cfg.xml