-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate 3 initialization issues
PostPosted: Fri Jul 01, 2005 11:53 am 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Hello there! Since Hibernate 3 all associations are lazy This brings a bit of problem with lazy instatiation, I guess.

Let's examine this example

User
car : Car (lazy)

Car
manufacturer: Manufacturer (lazy)

Manufacturer
id
name


Ok, So I load User and then Hibernate.Initialize(car); that's ok. So in my view tier:

user.getCar().getManufacturer().getName() -> exception.

Today on Hibernate 2 I have an utility method that initializes every collection I need on a given class, but it lacks initialization on deeper object associations like the one above, this is my method:

public Entity initialize(Entity entity, String[] initialize){
try{
Session session = getCurrentSession();
session.lock(entity,LockMode.NONE);
if(initialize != null){
for(int i=0;i<initialize.length;i++){
Hibernate.initialize(PropertyUtils.getProperty(entity,initialize[i]));
}
}
}catch(Exception e){
e.printStackTrace();
}finally{
closeSession();
}
return entity;
}

How can one accomplish that?

Regards


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

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.