I know it helps you not really further but in my app I do it in the the same way you do it in your example. But it works in my app. And I must say that I use many lazy associations.
For getting the stub of my facades I am using the inital context.
Facade facade = (Facade) ctx.lookup(Facade.class.getName());
Maybe you try this?
I had the same problem with JBoss 4.0.3SP1. Are you really sure that you are using SP1?
The ServiceLocator.lookupEJB( Class ) uses InitialContext like your example.
I'm sure about JBoss 4.0.3SP1. What version do you use? Did you use the installer package or do some modification/upgrade?
I use JBoss 4.0.3SP1. I used the installer package and didn't make any mods or something like that.
Maybe you can try another approach:
Lookup for the facade outside of the transaction. I am not sure but maybe it helps!
Thaks for your help, but still doesn't work.
Are you sure you are using lazy collections outside EJB? In a Action Struts or JSF Managed Bean?
Are EJB's stateless or stateful? Are you using depency injection to get Entity Manager? Is entity manager extended?
I don't use Action Struts and I don't work with JSF Managed Beans either.
I simply work with servlets and JSPs. But I don't think that this really matters. In my application I only use stateless session beans as Data Access Objects and I use dependency injection all the time for my entity manager. Therefore my entity manager doesn't use the extended persistent context.
If it doesn't work with JSF or any other framework i would test my app within a simple servlet.
I change my code to a Servlet and still not working. Was just a test... really make no sense work in a Servlet and doesn't work in a JSF Managed Bean.
Are there any special configuration in your persistence.xml?
Could you show me the content of your persistence.xml properties tag? Specialy hibernate.transaction.factory_class and hibernate.transaction.manager_lookup_class.
I did notice that you looked up UserTransaction from the service locator... I'm not sure that will work.
I think maybe the problem is that the transaction you are getting is not the same as the transaction that is used by AplicacaoFacade.
If you want to use JSF with container managed transactions, try coding your managed bean as an EJB (look into JBoss SEAM). Or implement AplicacaoFacade as a POJO...
I made some test to figure out if lazy loading really works with UserTransactions!
And now I can definitly say that it works in my app. The facade I use is a stateless session bean that uses an injected entity manager. In my servlet I use the local interface. So from my point of view it is not a Jboss bug!
It might be really the problem that the the transaction you are creating is not the same the entity manager uses. But I am really not sure about this. Taking a look at your code tells me that everything should be OK!
There is one thing that we don't have covered yet! The entity beans!!
Please create a stateless session bean to test if the lazy loading works there. If not the problem is the entity bean mapping and has nothing to do with the UserTransaction!
What do you think about that?
Thanks Martin and Patrick!!!
It's working!!! The secret is that Martin is using a Local interface, while I was using a Remote interface for session façade.
that's great! I am happy that it works!
Thank you for this useful informations!!