Hi all, Here's my architecture (standard enough)
layer 1: jsps --> layer 2: struts actions --> layer 3: ejb3 stateless session bean managers --> layer 4: ejb3 domain objects I have a one-to-many relationship between User and Order, ie a User has many Orders. Now, I want to load the orders lazily. No problem, I specify the fetch type to be lazy on the relationship. So, when i get back a user, I don't get his orders. In order to get all his orders, I code a second method in one of my stateless session beans to specifically get all the orders for a given user eg, public List getOrdersForUser(String userName){ //first get the user for the username User u = entityManager.find(User.class,userName); //then call return user.getOrders(); } However, when I call this method I am getting the following exception failed to lazily initialize a collection of role: model.User.orders, no session or session was closed" when accessing the data of a "one-to-many" relation. not good. Now I have read the following post: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=73005 And in here it discusses the issue of transactions as the possible cause of the problem. I was under the impression that as soon as I entered a method in a stateless session bean, under the hood the hibernate session is re-opened and therefore I can access any level in the graph that I want. This is what I would expect with spring/hibernate etc. Is this not the case with ejb3 ??? Do I have to explicitly set the transaction attribute on all methods to get this working?? This is really a case of me not understanding the design as I thought I did. I understand the List will be detatched from the session when I return it back to the web tier (which is where the exception is being thrown), but the information is retrieved from the database in the stateless session bean, so there should be no problem?? please help! thanks , binario View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3929085#3929085 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3929085 ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user