Hi,
I need of a suggestion to improve the performance of my code.
For example: I have two entities, User and Address. Each User has a Address attribute, as LAZY association. This model is ok, because only sometimes I need to read the Address from a User.
But in a screen of my system I need to simulate a EAGER. I used the Hibernate.initialize() and everything works fine (Below is my sample working code).
Code:
...
String str_query = "select u from User u";
Query query = session.createQuery(str_query);
List<User> list = query.list();
for(User user: list){
Hibernate.initialize(user.getAddress());
}
return list;
...
My doubt is: How to improve this code? Because, if I have 1000 Users and 1000 Addresses, the Hibernate will do 1001 SQLs (1 sql to list all users, and 1000 sqls to retrieve the addresses).
There are a way to tell to hibernate to do a single SQL to retrieve all required addresses?
Please, help me!
Thanks a lot!
Claudiney