對於Query接口的list()方法與iterator()方法來說都可以實現獲取查詢的對象但是list()方法返回的每個對象都是完整的(對象中的每個屬性都被表中的字段填充上了)而iterator()方法所返回的對象中僅包含主鍵值(標示符)只有當對iterator()中的對象進行操作時hibernate才會向數據庫再次發送sql語句來獲取該對象的屬性值
一對多雙向關聯配置customer與order一對多的關系
[java]
public class Customer {
private Long id;
private String name;
private Set<Order> orders;//一對多通過該變量可以引用到對應Order集合對象
…get/set方法省略
}
[java]
public class Order {
private Long id;
private String orderNumber;
private Customer customer;//多對一通過該變量可以引用到關聯的customer對象
…get/set方法省略
}
Customerhbmxml
[html]
<hibernatemapping>
<class name=combsihibernateCustomer table=tb_customer>
<id name=id column=id type=long>
<generator class=increment></generator>
</id>
<property name=name length= type=string column=name></property>
<set name=orders cascade=saveupdate inverse=true>
<key column=customer_id></key>
<onetomany class=combsihibernateOrder/>
</set>
</class>
</hibernatemapping>
Orderhbmxml
[html]
<hibernatemapping>
<class name=combsihibernateOrder table=tb_order>
<id name=id column=id type=long>
<generator class=increment></generator>
</id>
<property name=orderNumber column=orderNumber type=string></property>
<manytoone name=customer class=combsihibernateCustomer column=customer_id></manytoone>
</class>
</hibernatemapping>
From:http://tw.wingwit.com/Article/program/Java/ky/201311/27867.html