[EJB 3.0] - org.hibernate.LazyInitializationException: failed to lazily
by jtalafous
I'm on the learning curve when it comes to using EJB 3.0 inside a
JBoss EJB container. I have developed all my entity beans and can
persist them successfully with JPA annotations outside an EJB
container (using Hibernate only) without a problem. it is only when I
am migrating to JBoss that I am having problems:
1.) I have an Entity which has several Lists as fields that get persisted.
2.) I have a stateful session bean (SFSB) which has the entityManager
annotated with @PersistenceContext(unitName = "myPU",
type=PersistenceContextType.EXTENDED)
and this works great to persist an entity and immediately retrieve it
in the same method. Without this annotation, retrieving the Entity
will throw this exception:
org.hibernate.LazyInitializationException: failed to lazily initialize
a collection of role: MyEntityClass, no session or session was closed
3.) I can persist the Entity and immediately retrieve it in the same
method. However, if I keep JBoss running, and restart the VM and
retrieve the Entity with the exact same SFSB again, the exception in
bullet 2 above is thrown. (BTW, Setting to EAGER loading isn't an
option for my requirements.)
It seems that the entityManager session is being closed in one way or
another, despite the inclusion of the annotation in bullet 2 above.
I'm not clear as to if this should happen or not. I am assuming that
a stateful session bean should be able to hold open a JPA
entityManager session indefinitely. Is this a good assumption?
Also, looking at the JBoss server.log, I am seeing that my SFSB is
being passivated. How is the entityManager session supposed to
progress through passivation? I would expect it wouldn't. After
activation, am I supposed to somehow restore the entityManager
session?
Thanks in advance for any tip or hints to get me going.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009162#4009162
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009162
17Â years, 11Â months
[JBoss Messaging] - Re: MDB deployment causes connection timeout error
by alllle
It seems that it is actually a lease / renew problem for MDB.
After look into the source code of JBoss remoting, it seems that the Messaging simply removes the client connection endpoint when it is notified by the jboss remoting.Lease class. The Lease class has a timer that checks if the client has renewed its lease or not. If not, it considers it as a dead connection and notifies the Messaging callback listener:
private class LeaseTimerTask extends TimerTask
| {
|
| protected boolean running = true;
|
| /**
| * The action to be performed by this timer task.
| */
| public void execute()
| {
| if(running)
| {
| if(leaseUpdated)
| {
| leaseUpdated = false;
| leaseTimer.schedule(this, leaseWindow);
| }
| else
| {
| stopLease();
| notifier.connectionLost(locatorURL, clientSessionId, requestPayload);
| }
| }
| }
| }
|
My question is then: how to configure Messaging to auto renew its connection lease on a deployed MDB? I looked into the jboss-messaging.sar\remoting-service.xml and there is a leasePeriod setting. I am not sure how to change it, as MDB would require an infinite lease period then.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009158#4009158
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009158
17Â years, 11Â months
[JBoss Seam] - Re: Does DataModelSelection work in a Stateless Session Bean
by twocoasttb
Ok. I understand why PAGE scope is appropriate, and recognize why it's the right scope for my finder bean. A conversation isn't required until an item in the list is selected for editing. A SFSB can't have PAGE scope (right?), so I assume the DataModel should. So my finder bean now looks like this:
@SuppressWarnings("serial")
| @Stateful
| @Name("organizationFinder")
| public class OrganizationFinderBean implements OrganizationFinder, Serializable {
|
| @PersistenceContext
| private EntityManager em;
|
| @In (required=false)
| @Out (required=false)
| private Organization organization;
|
| @DataModel(scope=ScopeType.PAGE)
| private List<Organization> organizations;
|
| @DataModelSelection
| Organization selectedOrganization;
|
| @Logger
| private Log log;
|
| @SuppressWarnings("unchecked")
| @Factory
| public void getOrganizations() {
| organizations = em.createQuery("select o from Organization o order by o.name")
| .getResultList();
| }
|
| @Begin
| public String newOrganization() {
| organization = new Organization();
| return "newOrganization";
| }
|
| @Begin
| public String selectOrganization() {
| organization = em.merge(selectedOrganization);
| return "editOrganization";
| }
|
| @Remove @Destroy
| public void destroy() {}
| }
and my dataTable looks like this:
<h:dataTable id="organizations" value="#{organizations}" var="o">
| <h:column>
| <f:facet name="header">Prefix</f:facet>
| #{o.prefix}
| </h:column>
| <h:column>
| <f:facet name="header">Name</f:facet>
| #{o.name}
| </h:column>
| <h:column>
| <f:facet name="header">Legal Name</f:facet>
| #{o.legalName}
| </h:column>
| <h:column>
| <f:facet name="header">Action</f:facet>
| <s:link id="editOrganization" value="Edit"
| action="#{organizationFinder.selectOrganization}"/>
| </h:column>
| </h:dataTable>
When I select an item in the list I get the following exception:
javax.ejb.EJBException: java.lang.IllegalArgumentException: attempt to create merge event with null entity
Based on a post I just saw, I think I'll try injecting the DataModelSelection directly into my edit bean. It seems though, based on prior comments and reading the docs, that the above should work. I assume I'm missing something stupid... Any ideas will be much appreciated.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009154#4009154
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009154
17Â years, 11Â months
[JBoss AOP] - Re: How do I access security info in a Interceport class?
by peixubin
I write the following class to init SecurityContext.currentDomain member.
MyInterceptorFactory.java:
| ...
| public Object createPerClass(Advisor advisor)
| {
| if (log.isDebugEnabled()) {
| log.debug("enter createPerClass");
| }
|
|
| AuthenticationManager manager = (AuthenticationManager) advisor.getDefaultMetaData().getMetaData("security", "authentication-manager");
| if (manager == null) {
| if (log.isDebugEnabled()) {
| log.debug("search manager");
| }
|
| try {
| manager = (AuthenticationManager) new InitialContext().lookup("java:/jaas/ydxt-domain2");
| }
| catch (NamingException e) {
| throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
| }
| }
| if (manager == null) throw new RuntimeException("Unable to find Security Domain");
| return new MyInterceptor(manager);
| }
| ...
|
|
MyInterceptor.java:
| ...
| public Object invoke(org.jboss.aop.joinpoint.Invocation invocation) throws Throwable {
| if (log.isDebugEnabled()) {
| log.debug("enter MyInterceptor");
| }
|
|
| Object oldDomain = SecurityContext.getCurrentDomain().get();
| try {
| SecurityContext.getCurrentDomain().set(authenticationManager);
| return invocation.invokeNext();
| }
| finally {
| SecurityContext.getCurrentDomain().set(oldDomain);
| }
| }
| ...
|
My SecurityContext.java,extend from org.jboss.aspects.security.SecurityContext:
|
| public class SecurityContext extends org.jboss.aspects.security.SecurityContext {
|
|
| public static ThreadLocal getCurrentDomain() {
| return currentDomain;
| }
|
| }
|
|
in jboss-aop.xml:
| ...
| <bind pointcut="all((a)ydxt.ejb.aop.FydSecurity)">
| <interceptor factory="ydxt.ejb.aop.MyInterceptorFactory" scope="PER_CLASS"/>
| <advice name="checkRight" aspect="ydxt.ejb.aop.FydSecurityInterceptor"/>
| </bind>
| ...
|
the isCallerInRole and isCurrentInRole work fine !!!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4009146#4009146
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4009146
17Â years, 11Â months