2 Replies Latest reply on Mar 31, 2006 9:24 AM by Hamdy Farid

    how to get entitymanager within MBean

    Hamdy Farid Newbie

      As the subject stated, I am trying to get access to my entity manager within Service MBean. The entity manager life time is associated with the life time with the service MBean

      my par and sar are packaged within the same ear, how can I declare dependancy of the sar on the par (dependancy on the entity manager)


        • 1. Re: how to get entitymanager within MBean
          Emmanuel Bernard Master

          you mean EM or EMF.
          I don't see the usefulness of managing the EM lifecycle through JMX

          • 2. Re: how to get entitymanager within MBean
            Hamdy Farid Newbie

            I found some answers (after one long night and tons of coffee :-) )
            - To declare the dependancy between SAR and PAR within the same ear file
            in your jboss-service.xml (within the sar]

             <mbean code="com.bla.bla.MYService" name="bla.bla:service=MYS">
             <depends>jboss.j2ee:service=EJB3,module=put your par file here</depends>

            - To access the entity manager from MBean
            First you need to advertise your entity manager factor
            in your persistance.xml
            <property name="jboss.entity.manager.jndi.name" value="java:/EntityManagers/myem"/>
            <property name="jboss.entity.manager.factory.jndi.name" value="java:/EntityManagersFactory/myemFac"/>

            In the service MBean , override startService(). lookup your entity manager factory and call createEntityManger to get yourself an instance of the em.... I created EXTENDED em and it worked for me

            Why I am doing all of that... here is the problem I am trying to solve (if you know better solution, please share it with all of us)
            - I have to maintain a graph, the graph vertcies and the edges are persisted in the db using EJB3 entity beans
            - my clients (lots of concurrent ones), are travesing portions of the graph, updating information in the graph
            - The first solution was to use optimistic locks (@version).... that killed me as some portion of the graph was being updated by multiple clients at the same time .... lots and lots of exceptions

            - Second solution. In a ServiceMBean, I instantiated a JGraph, loaded all my entities into the JGraph

            - my clients can call methods of a SLSB that forward the call to the service MBean
            - In the MBean I am controlling the locking mechanism using semaphores per vertex/Edge

            Problems with my solution:
            - In cluster deployment, how can I replicate my JGraph information??