[EJB 3.0] - Re: How to lazily load collections?
by ALRubinger
Sorry; I assumed you were trying to iterate over the collection immediately after calling "refresh". Where is the code generating the error? Not in that SLSB snippit posted, but in the JSP?
The List returned from the EntityManager will be a Hibernate Collections class with a reference to the current session. If you're just looking to get a "snapshot" of the current data in there at the time its requested, you can create a new List, put all of the items in the Entity bean's version in it, and safely return your list for use outside of the session/transaction. Assuming you're getting the error in the JSP:
public List<TdmAlerts> getAlertsFromEntity(MyEntity entity) {
| entityManager.refresh(entity);
| List<TdmAlerts> tdmAlerts = new ArrayList<TdmAlerts>();
| tdmAlerts.addAll(entity.getTdmAlerts());
| return tdmAlerts;
| }
...I think should do it. Or use a TO/VO.
Manually closing is done by something like:
((HibernateEntityManager)entityManager.getDelegate()).getSession().close(); ... or similar
S,
ALR
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978631#3978631
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978631
19 years, 8 months
[EJB 3.0] - Re: Local and Remote interfaces required in EJB3
by esfahan
Sure, I understand that the client only gets a proxy to some interfaces and the bean implementation has of course to stay on the server. What I don't understand is why this interfaces could not be generated dynamically.
For example using some imaginary annoations here:
@Stateful
| @Local (interface="FooLocal")
| public class FooBean
| {
| @LocalMethod
| public void foo();
|
| @LocalMethod
| public void bar();
| }
Wouldn't this be enough information for creating the client interface:
public interface FooLocal
| {
| public void foo();
| public void bar();
| }
Given you would stick to some sort of naming standard you could provide even default values for the names of the local and remote interfaces.
Of course FooBean does not implement an interface now anymore, but invocations could be handled by some sort of dynamic proxy, right?
--Hardy
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978628#3978628
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978628
19 years, 8 months
[EJB 3.0] - Re: How to lazily load collections?
by michael.litherland
Hi,
Thanks for the reply.
I've tried two ways, most recently I'm doing this in an EJB stateless session bean:
| public List<TdmAlerts> getAlertsFromEntity(MyEntity entity) {
| entityManager.refresh(entity);
| return entity.getTdmAlerts();
| }
|
Previously I was just using this same bean to return the entity after doing an entityManager.find and within my JSF application wrapping the List returned from the entity in a ListDataModel for display in the JSP. This worked before switching to LAZY. Also, I'm not closing the session and I can't even find in the java doc how to do such a thing if I wanted to! I've certainly hunted around for some clues on how to work within the session to bypass this problem.
Thanks again for the help.
Mike
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978625#3978625
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978625
19 years, 8 months