日期:2014-05-19 浏览次数:20710 次
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> </props> </property> <property name="mappingResources"> <list> <value>cn/java/ORM/Person.hbm.xml</value> <value>cn/java/ORM/Category.hbm.xml</value> <value>cn/java/ORM/Orders.hbm.xml</value> <value>cn/java/ORM/Books.hbm.xml</value> </list> </property>
public class Books { private int id; private String name; private int money; private int inventory;// 库存量 private int buyQuantity;// 买入量 private String comment;// 评论 private Person person;//收藏字段 private Category category;//种类字段 private Orders orders;//订单字段 public Books() { }
<hibernate-mapping package="cn.java.ORM"> <class name="Books" table="BOOKS" lazy="true"> <id name="id"> <generator class="sequence" /> </id> <property name="name" /> <property name="money" /> <property name="inventory" /> <property name="buyQuantity" /> <property name="comment" /> <!-- 对应 ID字段用于收藏 --> <many-to-one name="person" column="person_id" class="Person" /> <!-- 用于分种类 --> <many-to-one name="category" column="category_id" class="Category" /> <!-- 用于下订单(购物车) --> <many-to-one name="orders" column="orders_id" class="Orders" /> </class> </hibernate-mapping>