[EJB 3.0] - How to lazily load collections?
by michael.litherland
Hi,
I have an EJB3 entity that contains a collection of other entities. The collection is both very rarely used and extremely large so I'd really rather not eagerly load it (in fact I can't, it makes the site slow to a crawl). The problem is that I don't know how to get around the LazyInitializationException when you specify the collection as lazy.
I tried creating a method in my EBJ3 BL layer that did a entityManager.refresh(entity) and then called the entity.getCollection method, but that doesn't help.
I've googled all over and searched here, but I can't figure out how to successfully load a lazy collection in EJB3. Removing the relationship from the entities would work, but that seems like it should be unnecessary. This is the error I want to avoid:
| Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ati.raa.entities.TdmSites.tdmAlerts, no session or session was closed
|
And the snippit:
| @OneToMany(mappedBy = "tdmSite", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
| private List<TdmAlerts> tdmAlerts;
|
This has got to be simple and I'm just missing something. Can anyone help me out?
Thanks,
Mike
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978604#3978604
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978604
19 years, 8 months
[EJB 3.0] - Local and Remote interfaces required in EJB3
by esfahan
Hi there,
I am trying to get started with EJB3 and Seam and have a question regarding remote and local interfaces. It seems to define a stateful bean I have to do something along this lines:
@Local
public interface Foo
{
...
}
@Stateful
public class FooBean implements Foo
{
...
}
I have to specify and interface which I annoate with @Local and then I need an actual bean implementation which I annoate with @Stateful. However, I thought that in EJB3 I don't need interfaces anymore. I hoped to be able to annoate a simple POJO. I recall reading somewhere that if eg I annotate a POJO as Stateful with no other annotation per default all public methods become part of the business interface. If I try to put the @Local annotation on FooBean itself removing the 'implements Foo' I get
java.lang.RuntimeException: bean class has no local, webservice, or remote interfaces defined and does not implement at least one business interface
Why are these interfaces still required. I could imagine something like this
@Stateful
public class FooBean implements Foo
{
@LocalMethod
public void foo();
@LocalMethod
@RemoteMethod
public void bar();
}
Why can I not annotate in a simple POJO which of my methods are exposed in the local/remote business interface. Of course I realize how much simpler EJB3 had become compared to EJB2, but without beeing able to annotate the buisness interface in the actual POJO it seems to be a half hearted apporach.
Am I missing something?
--Hardy
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978601#3978601
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978601
19 years, 8 months
[JBoss Eclipse IDE (users)] - Re: JBoss Ide 2.0.0-Beta2 problem
by rob.stryker@jboss.com
"msell" wrote : "The selected configuration ("JBoss-5.0-Alpha") does not contain the expected EJB3 libraries. Please install JBoss with EJB3 enabled, or try another configuration."
This is intended. If your jboss installation does not contain the path server/jboss-ejb3.jar then it will not create an ejb3 project.
"msell" wrote : Attempting to "Create a JBoss Server" results in the same problem that "giordano" reported.
Once you create a new server, simply selecting any of the servers inside the dialog box should definitely enable the finish button, even if the finish doesn't work, the button itself *WILL* be enabled. You must SELECT the server from the list to enable the button though.
So to recap, after creating a new server from the dialog, you must select it to enable the finish button. And if the server installation does not contain a server/jboss-ejb3.jar library file, you will not be able to make the EJB3 project and an error message will pop up AFTER pressing finish.
If anyone's experiences contradict me, PLEASE write back with more information.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978600#3978600
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978600
19 years, 8 months