Biljana thanks for your answer! I find why in the LAB's project it doesn't need the attribute Lazy="false" in Event.hbm.xml. It's cause the session is never closed (the line is commetted) as you can see in the pasted-code:
public Event find(Long id) throws DataAccessLayerException { Event event = null; try { startOperation(); event = (Event) session.load(Event.class, id); tx.commit(); } catch (HibernateException e) { handleException(e); } finally { //HibernateFactory.close(session); } return event; } Greetings! Federico Miralles ----- Original Message ----- From: Biljana Biljana To: Grupo J2EE ; federicomiral...@gmail.com Sent: Sunday, May 31, 2009 8:32 AM Subject: Re: [java ee programming] org.hibernate.LazyInitializationException ERROR Maybe I am stupid, but I don't understend why you have lazyInitializacion, you use some join? This is doesn't appear in EventDao? They use only ona table. Accordingly what you want to show and what your HQL query look like you use diferent fetch. But this is not good explain to me , so just have a look in topic Hibernate Join Fetch. --- On Sat, 5/30/09, federicomiral...@gmail.com <federicomiral...@gmail.com> wrote: From: federicomiral...@gmail.com <federicomiral...@gmail.com> Subject: [java ee programming] org.hibernate.LazyInitializationException ERROR To: "Grupo J2EE" <java-ee-j2ee-programming-with-passion@googlegroups.com> Date: Saturday, May 30, 2009, 12:45 PM Hi everyone!!! I don't understand why when i run the following code (using DAO pattern): Hobby hobby = hobbyDao.find(h.getMyHobbyId()); System.out.println("Hobby = " + hobby.getHobby()); System.out.println("Years of practice = "+hobby.getYearIstartedThisHobby()); it throws an exception: GRAVE: could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150) at Hobby$$EnhancerByCGLIB$$cb36960a.getHobby(<generated>) at Main.main(Main.java:24) Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150) at Hobby$$EnhancerByCGLIB$$cb36960a.getHobby(<generated>) at Main.main(Main.java:24) Java Result: 1 The only way i figured out to avoid this is to DISABLED Lazy initialization by setting in Hobby.hbm.xml: <class name="Hobby" table="hobby" lazy="false"> ... The strange thing is that this code is based on "HibernateSimpleDaoInterface" project from LAB-3514 where Lazy="false" doesn't exist in Event.hbm.xml. I expecting that someone could clarify this. Thanks in advance! Federico Miralles Mendoza, ARGENTINA --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en -~----------~----~----~----~------~----~------~--~---