-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate.initialize()
PostPosted: Tue Mar 13, 2007 4:46 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 11:39 am
Posts: 24
I would like to ask something about Hibernate.initialize().
I have a pojo named Item.This pojo is LAZY.

So in my ItemDao class I get my pojo:

Code:
Item item = session.get(Item.class, itemId); -->THERE IS A SELECT HERE


Then I get the following list:

Code:
List  bids = item.getBids(); --->THERE IS NO QUERY HERE


and I iterate the bids list and it is then that I have a SECOND SELECT

However if after get the Item pojo I do sth like that:

Code:
Hibernate.initialize(item.getBids)  --> THERE IS A SELECT HERE

and if afterwards I iterate the list there are no selects.

My question is?What is the difference between the two ways I describe?
Why should I use Hibernate.initialize()?What does it offer?I see the same number of queries every time.


Any suggestions?


Top
 Profile  
 
 Post subject: Re: Hibernate.initialize()
PostPosted: Tue Mar 13, 2007 5:13 am 
Newbie

Joined: Tue Mar 13, 2007 4:15 am
Posts: 12
Location: Trivandrum
juanita wrote:
I would like to ask something about Hibernate.initialize().
I have a pojo named Item.This pojo is LAZY.

So in my ItemDao class I get my pojo:

Code:
Item item = session.get(Item.class, itemId); -->THERE IS A SELECT HERE


Then I get the following list:

Code:
List  bids = item.getBids(); --->THERE IS NO QUERY HERE


and I iterate the bids list and it is then that I have a SECOND SELECT

However if after get the Item pojo I do sth like that:

Code:
Hibernate.initialize(item.getBids)  --> THERE IS A SELECT HERE

and if afterwards I iterate the list there are no selects.

My question is?What is the difference between the two ways I describe?
Why should I use Hibernate.initialize()?What does it offer?I see the same number of queries every time.

Any suggestions?


The associated object inside a persistant class will be fetched lazily
you can disable it by giving lazy="false"

Hibernate.initialize() will
force the initialization of a proxy,as long as its Session is open

_________________
Regards
Belto


Top
 Profile  
 
 Post subject: Re: Hibernate.initialize()
PostPosted: Tue Mar 13, 2007 5:36 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 11:39 am
Posts: 24
Quote:
The associated object inside a persistant class will be fetched lazily
you can disable it by giving lazy="false"


No I want my pojo to be lazy.

Quote:
Hibernate.initialize() will
force the initialization of a proxy,as long as its Session is open.


So if I do not use Hibernate.initialiaze(), through iteration(where I can see SELECT) the initialization of a proxy is not initialized?
If not, what exactly the initialization of the proxy offers me?


Top
 Profile  
 
 Post subject: Re: Hibernate.initialize()
PostPosted: Tue Mar 13, 2007 6:00 am 
Newbie

Joined: Tue Mar 13, 2007 4:15 am
Posts: 12
Location: Trivandrum
set ur pojo lazily by setting the persistant class lazy ="false" in the mapping file in class tag

_________________
Regards
Belto


Top
 Profile  
 
 Post subject: Re: Hibernate.initialize()
PostPosted: Tue Mar 13, 2007 6:16 am 
Beginner
Beginner

Joined: Wed Jan 31, 2007 11:39 am
Posts: 24
I want my pojo to be lazy so lazy="false" is something I do not need.

What I am asking is what exactly the initialization of the proxy offers?
And if this is only offered when I use Hibernate.initialize()?

When I iterate the getBids collection and I have not used Hibernate.initialize() there is no initialization of the proxy?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.