由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Design question --- hibernate
相关主题
Hibernate questionjava的volatile
感觉JPA很鸡肋Singleton Session Bean
Team Lead Java Web Infrastructure Engineer ($130k-$200k)Re: Confused!
再问一个OR Mapping的问题Re: Entity EJB: anyone with real experience
请问hibernate这个功能如何实现?hehe, Neo (.NET Entity Objects)
How to disable hibernate second-level cache for an entityneed help from the J2EE expert
hibernate性能问题Entity Bean question
ArraList questionentity bean class for joint table
相关话题的讨论汇总
话题: design话题: do话题: entities话题: hibernate话题: eager
进入Java版参与讨论
1 (共1页)
c******n
发帖数: 4965
1
my model has 2 entities ,
A , B , related 1-1.
normally I do
A a = MyDaoForA.getA() ;
// do something with a
but sometimes right after the above code, I do
B b = a.getB();
so if in the first getA(), I eagerly fetch B too, I would save an
extra SELECT; but in cases where I don't run the latter B, it's a waste to
pull in too many entities through outer JOIN.
so MyDaoForA.getA() should have 2 versions, or even multiple versions, if I
have further C , D associated .....
how do you take care of this?
r*****s
发帖数: 985
2
that's exactly what your MyDaoForA is for
instead of annotating entities with "EAGER" fetching;
overloading the methods or put a flag parameter there;
otherwise you don't even need a MyDAOForA,
a baseDAO suffices.

to

【在 c******n 的大作中提到】
: my model has 2 entities ,
: A , B , related 1-1.
: normally I do
: A a = MyDaoForA.getA() ;
: // do something with a
: but sometimes right after the above code, I do
: B b = a.getB();
: so if in the first getA(), I eagerly fetch B too, I would save an
: extra SELECT; but in cases where I don't run the latter B, it's a waste to
: pull in too many entities through outer JOIN.

c******n
发帖数: 4965
3
sorry you mean MyDaoForA().getA() should load both A and B?
then in use cases where I need A only, it will be a waste, how to deal with
that?

【在 r*****s 的大作中提到】
: that's exactly what your MyDaoForA is for
: instead of annotating entities with "EAGER" fetching;
: overloading the methods or put a flag parameter there;
: otherwise you don't even need a MyDAOForA,
: a baseDAO suffices.
:
: to

t*******e
发帖数: 684
4
Set lazy as the default loading scheme, and apply eager in specific queries
when performance is significant.
r*****s
发帖数: 985
5
Maybe I don't fully get your question:
* where you need A only use MyDAOForA.getA()
* where you need A and B use MyDAOForA.getAandB()
or something like MyDAOForA.getA(Boolean doIneedB).
doesn't it solve your problem?
Do NOT put B in A as "Eager" in entity def;
instead set the fetch mode as EAGER in getAandB() if necessary,
or call .fetch(B) in your DAO impl.

with

【在 c******n 的大作中提到】
: sorry you mean MyDaoForA().getA() should load both A and B?
: then in use cases where I need A only, it will be a waste, how to deal with
: that?

1 (共1页)
进入Java版参与讨论
相关主题
entity bean class for joint table请问hibernate这个功能如何实现?
问个JPA的问题How to disable hibernate second-level cache for an entity
问一个Many to Many的设计问题hibernate性能问题
问个JDBC做查询的问题ArraList question
Hibernate questionjava的volatile
感觉JPA很鸡肋Singleton Session Bean
Team Lead Java Web Infrastructure Engineer ($130k-$200k)Re: Confused!
再问一个OR Mapping的问题Re: Entity EJB: anyone with real experience
相关话题的讨论汇总
话题: design话题: do话题: entities话题: hibernate话题: eager