beyanet.com wrote:


I use hibernate within JBoss 4 as follows:

InitialContext ctx = new InitialContext(); sessionfactory = (SessionFactory)ctx.lookup("java:/hibernate/SessionFactory"); session = sessionfactory.openSession(); transaction = session.beginTransaction(); orderSet = (Order)session.load(Order.class, orderNum); Hibernate.initialize(orderSet.getOrderItems()); transaction.commit(); session.close();

for example.

Yeah I though about this method, but it is rather complicated if I must initialize more complicated data structures. For example if I have beans OWNER,DOG,AWARD, where relation is - owner have many dogs, dog have many award. If I use lazy initialization I can easy print out everything. But I resign from lazy loading I must initialize collections by hand. So If have a owner I should initialize DOGS Collection. It is easy -> Hibernate.initialize(owner.getDogs()). But in next step I want to initialize all dog awards, to do that I must Iterate through getDogs Collection.

Iterator<Dog> it = owner.getDogs().iterator();
while (it.hasNext())  Hibernate.initialize(it.next);

So it is bit more complicated. But if we have more nested elements we want access the initialization become madness. So I think it is not worth to resign from lazy loading.

J.K.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to