从Customer到Order,配置在<set>标签中,batch-size表示一次查询几个客户的订单,而不查询的订单数量,配置为2,表示一次查询两个客户的订单数量
<hibernate-mapping> <class name="rock.lee.bean.Customer" table="customer" catalog="test" > <id name="id" column="id" type="int"> <generator class="native"></generator> </id> <set name="orders" cascade="save-update,delete,delete-orphan" inverse="true" fetch="select" lazy="true" batch-size="2"> <!-- customer表order是中所生成的外键列 --> <key column="customer_id"></key> <one-to-many class="rock.lee.bean.Order" /> </set> <property name="name" column="name" type="java.lang.String"></property> <property name="city" column="city" type="java.lang.String"></property> </class> </hibernate-mapping>
查询所有的Customer并且获得Order集合的大小
@Test public void test05() { Session session = HibernateUtils.openSession(); Transaction transaction = session.beginTransaction(); List<Customer> list = session.createQuery(" from Customer").list(); for (Customer c : list) { System.out.println(c.getOrders().size()); } transaction.commit(); session.close(); }
SQL:
Hibernate: select customer0_.id as id0_, customer0_.name as name0_, customer0_.city as city0_ from test.customer customer0_ Hibernate: select orders0_.customer_id as customer4_0_1_, orders0_.id as id1_, orders0_.id as id1_0_, orders0_.address as address1_0_, orders0_.money as money1_0_, orders0_.customer_id as customer4_1_0_ from test.orders orders0_ where orders0_.customer_id in ( ?, ? )
通过in条件查询order
从Orders到Customer配置在Customer.hbm.xml中的<class>标签中batch-size,一次查询几个客户
<hibernate-mapping> <class name="rock.lee.bean.Customer" table="customer" catalog="test" batch-size="2"> </hibernate-mapping>
检索策略的比较
相关推荐
NULL 博文链接:https://364232252.iteye.com/blog/2368890
No Hibernate Session bound to thread,没有绑定线程解决办法,找了好久才找到的
问题描述 用SpringBoot + Spring Data JPA操作数据库 项目启动的时候 报了一个错 SpringBoot的版本是2.2.6.RELEASE org.springframework.beans.factory.BeanCreationException: Error creating bean with name '...
NULL 博文链接:https://mvplee.iteye.com/blog/2239488
NULL 博文链接:https://mvplee.iteye.com/blog/2186102
NULL 博文链接:https://mvplee.iteye.com/blog/2186235
NULL 博文链接:https://mvplee.iteye.com/blog/2186283
NULL 博文链接:https://mvplee.iteye.com/blog/2186414
官网hibernate:问题说明: 1、安装整合通过; 2、整合时注意javassist-3.22.0-GA.jar与struts2.4的 javassist-3.20.0-GA.jar重复; 3、整合所需基础包以及整合需要的外部包,自己放到一个新建文件夹中,方便大家...
介绍了HIBERNATE的检索策略,可以此作为指引进行学习
NULL 博文链接:https://364232252.iteye.com/blog/2368725
Hibernate的检索策略包括类级别检索策略和关联级别检索策略。
hibernate5--4.检索方式及策略
hibernate-validator 5.3.5.Final jar包 ;desc:if you want validator your project
很多人都对Java在批量数据的处理方面是否是其合适的场所持有怀疑的念头,由此延伸,...下面以Hibernate为例来做为说明,假如我们真的不得不在Java中使用Hibernate来对数据进行批量处理的话。 向数据库插入100 000条数据
Hibernate.jar包,Hibernate可以应用在任何使用JDBC的场合,包含 hibernate-commons-annotations-4.0.1.Final.jar hibernate-core-4.1.12.Final.jar hibernate-ehcache-4.1.12.Final.jar hibernate-entitymanager-...
用于hibernate集成memcached作为二级缓存所需要的包,1.2.2版本
org.hibernate.TransactionException: JDBC rollback failed
整合了hibernate所需的全套jar包包括日志jar包以及mysql的连接jar包,希望对大家有所帮助
hibernate各个包 hibernate-testing: 支持单元测试。 hibernate-swarmcache:支持SwarmCache,一个简单而功能强大的分布式缓存机制。它使用IP组播来有效地在缓存的实例之间进行通信。它是快速提高集群式Web应用...