hibernate.cfg.xml
1 <?xml version='1.0' encoding='utf-8'?> 2 <!DOCTYPE hibernate-configuration PUBLIC 3 "-//Hibernate/Hibernate Configuration DTD//EN" 4 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 5 <hibernate-configuration> 6 <session-factory> 7 <property name="connection.url">jdbc:mysql://localhost:3306/ht1668webbuyer?useUnicode=true&characterEncoding=UTF-8</property> 8 <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 9 <property name="connection.username">root</property> 10 <property name="connection.password">root</property> 11 <property name="current_session_context_class">thread</property> 12 <property name="show_sql">true</property><!--显示sql语句--> 13 <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property> 14 <!--方言配置,用来更准确的产生sql语句--> 15 16 <!--把映射文件一定要加入资源文件中--> 17 <mapping resource="hbm/User.hbm.xml"/> 18 <mapping resource="hbm/UserDetails.hbm.xml"/> 19 <mapping resource="hbm/Goods.hbm.xml"/> 20 <mapping resource="hbm/GoodDetails.hbm.xml"/> 21 <mapping resource="hbm/BuyCar.hbm.xml"/> 22 <mapping resource="hbm/Order.hbm.xml"/> 23 <mapping resource="hbm/OrderDetails.hbm.xml"/> 24 <!-- DB schema will be updated if needed --> 25 <!-- <property name="hbm2ddl.auto">update</property> --> 26 </session-factory> 27 </hibernate-configuration>
User.hbm.xml
1 <?xml version='1.0' encoding='utf-8'?> 2 <!DOCTYPE hibernate-mapping PUBLIC 3 "-//Hibernate/Hibernate Mapping DTD//EN" 4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 5 <hibernate-mapping> 6 <class name="com.iotek.homework.model.User" table="users" schema="ht1668webbuyer"> 7 <id name="id" type="java.lang.String"> 8 <column name="id" sql-type="char" length="32"/> 9 </id> 10 <property name="name" type="java.lang.String"> 11 <column name="name" sql-type="varchar" length="255"/> 12 </property> 13 <property name="pass" type="java.lang.String"> 14 <column name="pass" sql-type="char" length="32"/> 15 </property> 16 <property name="age" type="java.lang.Integer"> 17 <column name="age" sql-type="int"/> 18 </property> 19 <property name="img" type="java.lang.String"> 20 <column name="img" sql-type="char" length="32"/> 21 </property> 22 <!--cascade 表示级联, 23 lazy false表示非懒加载,懒加载的意思为,在取user时不取set中的所有值, 24 inverse 默认为false,用来确认外键id是否有值, 25 但是正常配置后,不可能出现外键id为null,所以不需要--> 26 <set name="userDetailses" cascade="all" lazy="false"> 27 <key column="userid"/> 28 <one-to-many class="com.iotek.homework.model.UserDetails"/> 29 </set> 30 </class> 31 </hibernate-mapping>