3

Hibernate的fetch问题,都琢磨一晚上了

 5 months ago
source link: https://www.jdon.com/31760.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Hibernate的fetch问题,都琢磨一晚上了

xml里lazy设置true,java里这么写:

result = s.createCriteria(JtsUser.class)
.setFetchMode("jtsHistories", FetchMode.JOIN)
.add(Restrictions.idEq(2))
.list();
此时result.size为4,但xml里lazy设置false,java里这么写
result = s.createCriteria(JtsUser.class)
.add(Restrictions.idEq(2))
.list();
result.size就为1了,按理说两种写发是等价的.
附:JtsUser包含jtsHistories,idEq(2)的JtsUser对应4个jtsHistory记录

hibernate对象映射的一个问题。

最近在研究hibernate。 但是我的书上面对有一个地方讲解的并不太好。 设想这样一个场景,我需要用compo.

使用Hibernate如何解决这样的场景呢!

一个订单系统,使用Hibernate来建模就会包含Order、OrderItem、Product这么几种类型,其中Order.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK