3 Replies Latest reply on Dec 13, 2007 2:10 PM by vanyatka

    @Startup and hbm2ddl

    vanyatka

      Hi,

      I've run into the following problem. I need to progammatically populate entity tables whenever upon the startup of the application. I thought that an application-scoped component, annotated with the @Startup would be the ideal place for placing those em-related statements.

      However, apparently there is a conflict with the hbm2ddl, that is still running (or not yet finished exporting DB schema) by the time the application-scoped component is created and initialised. The log shows that Seam context is initialised even before the hbm2ddl is run, i.e. before the tables are created in my case, which makes my initial assumption incorrect.

      Where can I put my custom DB init statements so that they run after hbm2ddl has done its job?

      Thanks,


        • 1. Re: @Startup and hbm2ddl
          vanyatka

          Can anyone confirm/deny that entityManager cannot be used in @Startup components while hbm2ddl is being used?

          • 2. Re: @Startup and hbm2ddl
            matt.drees

            If you're using an EntityManagerFactory component (i.e., you're not using the app server's EMF), then the hbm2ddl is run by entityManagerFactory's @Create method. So your @Startup component depends on the database, then you can denote the dependency in the annotation:

            @Startup(depends={"yourEntityManagerFactoryNameHere"})
            

            and your component's @Create method will be run afterwards.


            However, instead of using an application-scope/@Startup component, I'd recommend using an observer of the org.jboss.seam.postInitialization event. It's a bit cleaner, IMO.

            • 3. Re: @Startup and hbm2ddl
              vanyatka

              Thanks, matt!

              Your suggestion with "depend" annotation totally worked. And, also, it helped me with another issue I was having:
              http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112686#4112686

              I'll definitely give the observer a try, never used any observers before.