JPA中的对象导航查询及其lazy属性

这里和hibernate中的对象导航查询特性是一样的,参照下例:

//对象导航查询
	@Test
	public void testFind() {
		EntityManager em = MyJPAUtils.getEntityManager();
		EntityTransaction tx = em.getTransaction();
		tx.begin();
		Customer customer = em.find(Customer.class, Integer.parseInt("3"));
		System.out.println(customer);
		Set<Contact> contacts = customer.getContacts();
		System.out.println(contacts);
		tx.commit();
		em.close();
	}

这是结果:

Hibernate: 
    select
        customer0_.id as id1_1_0_,
        customer0_.address as address2_1_0_,
        customer0_.level as level3_1_0_,
        customer0_.name as name4_1_0_ 
    from
        customer customer0_ 
    where
        customer0_.id=?
Customer [id=3, name=新客户, address=null, level=null]
Hibernate: 
    select
        contacts0_.customer_id as customer5_0_0_,
        contacts0_.id as id1_0_0_,
        contacts0_.id as id1_0_1_,
        contacts0_.address as address2_0_1_,
        contacts0_.customer_id as customer5_0_1_,
        contacts0_.name as name3_0_1_,
        contacts0_.phone as phone4_0_1_ 
    from
        contact contacts0_ 
    where
        contacts0_.customer_id=?
[Contact [id=1, name=新联系人, address=null, phone=null]]
这里我并没有配置,因为jpa中默认一对多的导航查询是lazy的,而多对一的是eager(立即)。且在jpa中此属性名称为fetch。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值