users@glassfish.java.net

Re: Singleton EJB startup order

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Fri, 25 Feb 2011 13:12:13 -0800

Laird,

Singletons can access JPA during startup. So all mappings are processed
first.

-marina

Laird Nelson wrote:
> I had a question regarding @Singleton EJBs annotated with @Startup,
> specifically as they relate to persistence units.
>
> Liquibase (http://liquibase.org) has a ServletContextListener facility
> that allows it to perform some sanity checks against the database on
> application startup. However, when a failure occurs here, deployment
> is aborted, and Glassfish is left in an inconsistent state and future
> deployments fail. Leaving aside the obvious heinous Glassfish bug
> here, I don't really want to use a ServletContextListener for startup
> operations, as that's really just a convenient side effect and smells
> like a hack.
>
> Enter EJB 3.1 and its @Startup beans, which are clearly designed to
> perform startup activities for a Java EE application.
>
> My question is: do these beans get processed before JPA gets
> involved? I would like to be able to perform database sanity checks
> before any JPA mappings are processed.
>
> The EJB 3.1 specification says only this:
>
> the container must initialize the Singleton bean instance during the
> application startup sequence. The container must initialize all such
> startup-time Singletons before any external client requests (that is,
> client requests originating outside of the application) are delivered
> to any enterprise bean components in the application.
>
> Thanks,
> Laird