5 Replies Latest reply on Jun 17, 2013 2:15 AM by Wolf-Dieter Fink

    Jboss EAP 6.1.0 alpha - Unable to Connect to Entity Bean from Another Entity Bean

    ANAND KUMAR GEORGE PREM KUMAR Newbie

      I am currently doing migration of ejb2.1 applications from Jboss 4.3 to Jboss 6.1.0 alpha EAP.

       

      In my application, an entity bean named Package_Bean from which am getting reference to another local entity bean local home MaterialSet_LocalHome. Both of them are in the same EAR.

       

      In the below highlighted line, the code is just getting stuck . The code flow never proceeds after this line when we try to get value from the MaterialSet_Local from Package_Bean. Attached is the ejb-jar.xml for reference.

       

       

       

      Code snippet from Package_Bean trying to get values from the returned MaterialSet_Local:


      MaterialSet_Local materialset = getCurrentMaterialSet();

                  System.out.println("Inside the getUpdateSeverity method of Package_Bean 1");

                  System.out.println("Inside the getUpdateSeverity method of Package_Bean 1 materialset"+materialset);

                  String stocktypeId = materialset.getStockTypeId();

       

       

      Code snippet of returning reference of MaterialSet Entity Bean:

       

      private EJBLocalObject doDerefId(String id, String partitionName, EJBLocalHome localHome)

              throws FinderException

          {

       

              System.out.println("****************************Inside doDerefId ****************************");

              System.out.println("****************************Inside doDerefId id ****************************"+id);

              System.out.println("****************************Inside doDerefId partitionName****************************"+partitionName);

              System.out.println("****************************Inside doDerefId localHome****************************"+localHome);

       

              if( id == null )

                  return null;

       

              try

              {

                  Method findByPrimaryKey = localHome.getClass().getMethod(

                          "findByPrimaryKey",

                          new Class[] { PartitionedPK.class } );

       

                  System.out.println("****************************Inside doDerefId 111111111****************************");

       

                  EJBLocalObject localBean = (EJBLocalObject) findByPrimaryKey.invoke(

                          localHome,

                          new Object[] { new PartitionedPK( id, partitionName ) } );

                  System.out.println("****************************Inside doDerefId 111111111 localBean****************************"+localBean);

                  return localBean;

              }

              catch( InvocationTargetException ite)

              {

                  Throwable originalException = ite.getTargetException();

                  if( originalException instanceof FinderException )

                      throw (FinderException)originalException;

                  else if (originalException instanceof Exception )

                      throw new EJBException((Exception)originalException);

                  else

                      throw new EJBException(ite);

              }

              catch( Exception e )

              {

                  throw new EJBException( e );

              }

          }

        • 1. Re: Jboss EAP 6.1.0 alpha - Unable to Connect to Entity Bean from Another Entity Bean
          Wolf-Dieter Fink Master

          Did you use CMR for the relation?

          Maybe you should add logging TRACE for org.jboss.as.cmp  and attach the logfile

          • 2. Re: Jboss EAP 6.1.0 alpha - Unable to Connect to Entity Bean from Another Entity Bean
            ANAND KUMAR GEORGE PREM KUMAR Newbie

            I have attached the server log. By enabling the jboss cmp as below..

             

            <logger category="org.jboss.as.cmp">

                            <level name="DEBUG"/>

                        </logger>

             

             

             

            Kindly refer to the line 39618 in the logs. That is the point it is getting stuck after getting the EJB proxy.

             

            Thanks

            • 3. Re: Jboss EAP 6.1.0 alpha - Unable to Connect to Entity Bean from Another Entity Bean
              Wolf-Dieter Fink Master

              I did not see any cmp/cmr related SQL debugging.

              Did you use BMP entities?

              • 4. Re: Jboss EAP 6.1.0 alpha - Unable to Connect to Entity Bean from Another Entity Bean
                ANAND KUMAR GEORGE PREM KUMAR Newbie

                we don't use BMP entities. All our entity beans extends the below class.

                 

                 

                /*

                *     EntityBeanAdapter

                *

                *    Copyright (c) 2001 by Cards etc Pty Limited.

                *    Level 3-4, 695-699 George Street, Sydney NSW 2000, Australia

                *    All rights reserved.

                *

                *    This software is the confidential and proprietary information of

                *    Cards etc. ("Confidential Information").  You shall not

                *    disclose such Confidential Information and shall use it only in

                *    accordance with the terms of the license agreement you entered into

                *    any software of Cards etc.

                *

                *

                *     Created : Jun 28, 2002

                */

                package com.cassis.cx.base;

                 

                import com.cassis.fd.partition.Partition;

                import com.cassis.fd.partition.PartitionRegistry;

                 

                import javax.ejb.*;

                 

                import mobilematrix.codec.MessageEnvelope;

                import mobilematrix.codec.MessageProperties;

                 

                import java.util.Date;

                 

                /**

                * Base class for all EntityBean classes that provides default implementations for all

                * of the required methods.

                */

                public abstract class EntityBeanAdapter

                        extends AdapterBase

                        implements EntityBean, TimeoutListener

                {

                    /**

                     * the entity context for this bean

                     */

                    private EntityContext m_context;

                 

                    /**

                     * the data object for this bean (could be restricted to use between the Bean

                     * and JDBCMgr if appropriate)

                     */

                    private Object m_data;

                 

                    /**

                     * flag that indicates whether the JDBCMgr should be called in ejbStore to

                     * update the persistant state of this bean

                     */

                    private boolean m_isModified;

                 

                    /**

                     * Hang on to the EntityContext in case we need it later...

                     * @param context the EntityContext for this bean

                     */

                    public void setEntityContext( EntityContext context )

                    {

                        m_context = context;

                    }

                 

                    /**

                     * Forget about the EntityContext reference.

                     */

                    public void unsetEntityContext()

                    {

                        m_context = null;

                    }

                 

                    /**

                     * @return the EntityContext for this bean

                     */

                    protected EntityContext getContext()

                    {

                        return m_context;

                    }

                 

                    /**

                     * Default interface implementation.

                     */

                    public void ejbActivate()

                    {

                    }

                 

                    /**

                     * Default interface implementation.

                     */

                    public void ejbPassivate()

                    {

                    }

                 

                    /**

                     * Default interface implementation.

                     * Note that this method does NOT verify that a bean actualy exists

                     * in the database with this primary key. The parameter is simply

                     * returned as is. The reason for this is to reduce the database hit

                     * while loading a bean.

                     * @param pk the PartitionedPK primary key

                     * @return the PartitionedPK primary key

                     */

                    public PartitionedPK ejbFindByPrimaryKey( PartitionedPK pk )

                            throws FinderException

                    {

                        return pk;

                    }

                 

                    /**

                     * @return the data Object for this bean

                     */

                    public Object getDataObject()

                    {

                        System.out.println("Inside getDataObject method of getStockTypeId");

                        return m_data;

                    }

                 

                    /**

                     * Sets the data object.

                     * @param data

                     */

                    protected void setDataObject( Object data )

                    {

                        m_data = data;

                    }

                 

                    /**

                     * Get the Partition reference of this bean. This method is

                     * used to try and hide the fact that EntityContext.getPrimaryKey()

                     * will return a PartitionedPK that contains additional partition info

                     * that is only relevant while interacting with EntityJDBCMgrs.

                     * <p>IMPORTANT RULE: Never use the PartitionedPK class directly! Always

                     * use the helper methods in the Adapter classes and the EntityJDBCMgr.

                     * @return the Partition reference of this bean

                     */

                    protected Partition getPartition()

                    {

                        PartitionedPK pk = (PartitionedPK) m_context.getPrimaryKey();

                        return PartitionRegistry.getPartition( pk.getPartitionName() );

                    }

                 

                    /**

                     * Get the simple String id of this bean. This method is

                     * used to try and hide the fact that EntityContext.getPrimaryKey()

                     * will return a PartitionedPK that contains additional partition info

                     * that is only relevant while interacting with EntityJDBCMgrs.

                     * <p>IMPORTANT RULE: Never use the PartitionedPK class directly! Always

                     * use the helper methods in the Adapter classes and the EntityJDBCMgr.

                     * @return the simple String id of this bean

                     */

                    protected String getId()

                    {

                        PartitionedPK pk = (PartitionedPK) m_context.getPrimaryKey();

                        return pk.getId();

                    }

                 

                    /**

                     * Converts a String id into a Local entity bean reference given the

                     * bean local home class. This beans partition is used to resolve the

                     * reference.

                     * @param id the String id of the bean to resolve

                     * @param localHomeClass the EJBLocalHome Class object to use to create the reference

                     * @return the resolved EJBLocalObject reference

                     */

                    protected EJBLocalObject derefId( String id, Class localHomeClass )

                    {

                       

                        System.out.println("Inside derefId method in entry in Entity Bean Adapter  ###########################################");

                        System.out.println("Inside derefId method in entry in Entity Bean Adapter id ###########################################"+id);

                        System.out.println("Inside derefId method in entry in Entity Bean Adapter localHomeClass ###########################################"+localHomeClass);

                        System.out.println("Inside derefId method in entry in Entity Bean Adapter getPartition().getName() ###########################################"+getPartition().getName());

                        try

                        {

                            return super.derefId( id, getPartition().getName(), localHomeClass );

                        }

                        catch( FinderException e )

                        {

                            throw new EJBException( e );

                        }

                    }

                 

                    public PartitionedPK ejbCreate( Object obj, Partition p )

                            throws CreateException

                    {

                        // get a UUID from the id generator session bean

                        UUID_LocalHome idGenHome = (UUID_LocalHome) getLocalHome( UUID_LocalHome.class );

                        UUID_Local idGenLocal = idGenHome.create();

                        String id = idGenLocal.getUUID();

                 

                        // construct a pk from the uuid and partition

                        return createUsingId( id, obj, p );

                    }

                 

                    /**

                     * Default interface implementation.

                     */

                    public void ejbPostCreate( Object o, Partition p )

                    {

                    }

                 

                    /**

                     * Create method that can be used by beans that wish to supply their own

                     * id string instead of using the UUID generator. For example, configs

                     * use the config name as the id.

                     * @param obj

                     * @param id the string id to use when constructing the primary key

                     * @param p

                     * @return

                     * @throws CreateException

                     */

                    public PartitionedPK createUsingId( String id, Object obj, Partition p )

                            throws CreateException

                    {

                        EntityJDBCMgr mgr = getJDBCManager( p );

                        mgr.create( obj, id );

                        m_data = obj;

                        m_isModified = false;

                        return new PartitionedPK( id, p.getName() );

                    }

                 

                    public void ejbStore()

                    {

                        if( m_isModified )

                        {

                            EntityJDBCMgr mgr = getJDBCManager();

                            mgr.store( getDataObject(), getId() );

                            m_isModified = false;

                        }

                    }

                 

                    public void ejbRemove()

                            throws RemoveException

                    {

                        EntityJDBCMgr mgr = getJDBCManager();

                        mgr.remove( getId() );

                        m_data = null;

                        m_isModified = false;

                    }

                 

                    public void ejbLoad()

                    {

                        EntityJDBCMgr mgr = getJDBCManager();

                        m_data = mgr.load( getId() );

                        m_isModified = false;

                    }

                 

                    public void update( Object newData )

                    {

                        if( isUpdateAllowed( newData ) )

                        {

                            m_data = newData;

                            m_isModified = true;

                        }

                    }

                 

                    /**

                     * Get a JDBCMgr to use. This method relies on being able to call

                     * getPrimaryKey from the EJB context so it should NOT be used by

                     * home interface methods (create or finders...), they should use

                     * getJDBCMgr(Partition) instead.

                     * Subclasses are NOT allowed to reimplement this method.

                     * @return the EntityJDBCMgr subclass corresponding to this bean

                     */

                    protected final EntityJDBCMgr getJDBCManager()

                    {

                        return getJDBCManager( getPartition() );

                    }

                 

                    /**

                     * Get a JDBCMgr to use. This method uses the partition parameter

                     * to initialize the JDBCMgr. This method SHOULD be called by

                     * home interface methods (create or finders)

                     * Subclasses are NOT allowed to reimplement this method.

                     * @return the EntityJDBCMgr subclass corresponding to this bean

                     */

                    protected final EntityJDBCMgr getJDBCManager( Partition partition )

                    {

                        EntityJDBCMgr mgr = newJDBCManager();

                        mgr.setPartition( partition );

                        mgr.setSystemContext( getSystemContext( partition ) );

                        mgr.setEntityFactory( getEntityFactory( partition ) );

                        return mgr;

                    }

                 

                    /**

                     * Subclasses must implement this method so that we know what JDBC

                     * manager to talk to. HOWEVER, subclasses should NOT use this method

                     * to obtain a JDBCMgr. They should use one of the getJDBCMgr methods

                     * instead.

                     * @return the EntityJDBCMgr subclass corresponding to this bean

                     */

                    protected abstract EntityJDBCMgr newJDBCManager();

                 

                    /**

                     * Subclasses that do not want data to be updateable should override this method

                     */

                    protected boolean isUpdateAllowed( Object newData )

                    {

                        return true;

                    }

                 

                    /**

                     * Subclasses can use this method to determine whether the bean has been modified.

                     * @return whether this bean has been modified by any setter methods.

                     */

                    protected boolean isDirty()

                    {

                        return m_isModified;

                    }

                 

                    /**

                     * Subclasses should call this method whenever their data has been modified

                     * and needs to be saved to the database during ejbStore()

                     */

                    protected void markDirty()

                    {

                        m_isModified = true;

                    }

                 

                    /**

                     * Default implementation of the timer callback method. Should be overridden

                     * by any subclass that uses timers via the registerTimerEvent method. This

                     * method will be invoked when a registered timer for this bean expires.

                     * @param clientReference The String that was provided in the registerTimerEvent

                     * method.

                     */

                    public void onTimeout( String clientReference )

                    {

                    }

                 

                    /**

                     * Register this bean to receive a callback (via onTimeout()) when the time

                     * specified by eventTimestamp is reached. A TimedEvent is created that the

                     * EventTimer monitors and invokes the callback when the event expires.

                     * Currently only "one-off" timers are supported, there is no support for

                     * repeating timers etc.

                     * @param eventTimestamp The time that the client wishes to be notified via the

                     * callback.

                     * @param clientReference A String reference that the client can optionally supply

                     * that will be retained and returned in the onTimeout() callback method.

                     * @param clientLocalHome The client must supply a Class reference that represents

                     * his EJB Local Home interface (ie MyEntity_LocalHome.class) in order for the

                     * EventTimer to be able to find the client again.

                     * @return the Id of the TimedEvent that can be remembered and used to adjust the

                     * timeout time via the resetTimerEvent() method.

                     * @throws CreateException if unable to create the TimedEvent.

                     */

                    protected String registerTimerEvent( Date eventTimestamp, String clientReference,

                            Class clientLocalHome )

                            throws CreateException

                    {

                        TimedEvent_LocalHome timerLocalHome = (TimedEvent_LocalHome) getLocalHome(

                                TimedEvent_LocalHome.class );

                        TimedEvent_Local timer = timerLocalHome.create(

                                eventTimestamp,

                                clientReference,

                                getId(),

                                clientLocalHome,

                                getPartition() );

                        return getId( timer );

                    }

                 

                    /**

                     * Can be used to adjust the timeout value of a previously registered timer.

                     * @param timerId The Id of the timer that was returned by the registerTimerEvent()

                     * method.

                     * @param eventTimestamp The new timeout value for the timer.

                     */

                    protected void resetTimerEvent( String timerId, Date eventTimestamp )

                    {

                 

                        try

                        {

                            JMSDispatcher_LocalHome jmsDispatcherHome = (JMSDispatcher_LocalHome)

                                    getLocalHome( JMSDispatcher_LocalHome.class );

                            JMSDispatcher_Local jmsDispatcher = jmsDispatcherHome.create();

                            MessageEnvelope envelope = new MessageEnvelope();

                            envelope.setProperty( MessageProperties.TIMER_ID, timerId );

                            envelope.setBody( eventTimestamp );

                            jmsDispatcher.sendToEventTimer( envelope );

                        }

                        catch( CreateException e )

                        {

                            throw new EJBException( e );

                        }

                    }

                }

                • 5. Re: Jboss EAP 6.1.0 alpha - Unable to Connect to Entity Bean from Another Entity Bean
                  Wolf-Dieter Fink Master

                  This means you use BMP (BeanManagedPersistence) as you controll how to persist the data.

                  In that case you need to check the Tx workflow, as I said before there is a problem if you mark methods with wildcards (*) in this case the 'home' methods will not have this Tx attribute.

                  This may end in such locks as you migth have two different transactions deadlocking in the same thread.

                   

                  Also you should check whether where it get stucked, maybe use a debugger.