首页 > 代码库 > hibernate.cfg.xml
hibernate.cfg.xml
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> <property name="connection.username">root</property> <property name="connection.password">xxx</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="connection.url">jdbc:mysql://localhost:3306/hibernate_demo</property> <!--选择数据库方言--> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!--是否在console输出sql语句--> <property name="show_sql">true</property> <property name="format_sql">true</property> <!--update用于更新数据库表,常见create:如果数据库存在该表先删除再重建--> <property name="hbm2ddl.auto">update</property> <mapping resource="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是package.classname --> <class name="xml_onetomany.Students" table="STUDENTS"> <id name="sid" type="int"> <column name="SID" /> <!--assigned:初始化对象的时候SID要手动赋值,否则int默认为0,其他类型报错;native:自动增长,针对不同数据库意义不同--> <generator class="assigned" /> </id> <property name="name" type="java.lang.String"> <column name="NAME" /> </property> <property name="gender" type="java.lang.String"> <column name="GENDER" /> </property> <property name="address" type="java.lang.String"> <column name="ADDRESS" /> </property> </class> </hibernate-mapping>
hibernate.cfg.xml
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。