5 Replies Latest reply on Feb 4, 2002 5:39 AM by ppetit

    Create entity bean instances after deploy

    huimin li Newbie

      Hi,

      New to EJB and JBOSS, need some help.

      I created some CMP entity beans and have them successfully deployed. My server needs to
      initialize by creating some instances for the
      beans. The initial data for bean instances may
      come from a text file.

      The question is how to perform such initialization
      within the same JVM of the application server.
      I know I may do it by creating a client in a
      separated JVM. But it is much nicer to save a
      JVM.

      Thanks in advance.

        • 1. Re: Create entity bean instances after deploy
          David Jencks Master

          You could write an mbean to do that. In order to avoid problems with "who starts first" you may want to have your mbean programatically deploy your application, then create the entity beans. In 3.0 (cvs) I believe you can get the same effect by packing your ejb-jar inside a sar.

          • 2. Re: Create entity bean instances after deploy
            huimin li Newbie

            Thanks for your advice. Do you know any tutorial or
            example on how to do that ?

            • 3. Re: Create entity bean instances after deploy
              ppetit Newbie

              in case of... just another idea :
              I already got this kinf of need, I resolved it by calling a singleton class instance within the Create method of my EJB, so every time this EJB is instanciated by the container it referes to this singleton that performs tasks at initialization time of the ejb, you can implement other tasks in the postCreate method of your EJB as well.
              the singleton is usefull to insure not having multiple instances of a utility class jut needed once.
              your singelton class can perform any file load through a call to the ContextClassLoader, etc etc

              it was just an idea
              Philippe

              • 4. Re: Create entity bean instances after deploy
                huimin li Newbie

                Philippe

                Thanks for the suggestion. My understanding is, to be able to invoke the Create method of your EJB, you still need a invoker (client) which is outside the JVM of the application server. I need a way to invoke a bean method directly from application server's JVM after the bean is deployed. Is there any simple way to do it ? Seems this should be a common problem to deal with.

                • 5. Re: Create entity bean instances after deploy
                  ppetit Newbie

                  absolutely, you need a first call by a client within the same jvm or not.
                  but I can't figure why a server should need data if there's no client needing them...
                  at the very first call you can load data needed, just once in a cache, as I mentioned in my earlier message.

                  Philippe