4 Replies Latest reply on Jul 12, 2008 1:46 AM by Tony Herstell

    Getting something to run at Startup...

    Tony Herstell Master

      Finally back to doing some SEAM after a LONG LONG break!

      I want to run a Bean at startup... I simply want to pre-load some stuff in the database if it's not there already (another way would be to use import.sql but I don't want to guess all the Enum's)... I strongly use Enums (to cater for lack of Ada like Types. Anyhow...

      I try this (below) but I don't know what the incantation is to get the method to actually run (you can see me trying the constructor.

      This HAS to run before another bean... as he other bean expects the stuff to be in the database.

      public class InitialisationControllerImpl implements InitialisationController, Serializable {
               * Inject and leverage the Seam Logger.
              private Log log;
               * Inject the EJB3 Persistence context in EXTENDED mode so will remain
               * "current" over multiple client/server round trips.
              private EntityManager em;
              public InitialisationControllerImpl() {
                      log.info("Initialising Resource Kinds if required.");
                      for (ResourceKind eachResourceKind : ResourceKind.values()) {
                              Query theQuery = em.createQuery("from Resource r where r.kind = :kind").setParameter("kind", eachResourceKind);
                              if (theQuery.getResultList().isEmpty()) {
                                      Resource resource = new Resource();
                                      log.info("adding " + eachResourceKind);

      If a bean outjects an object I can get it to work ok; but the above code doesnt outject anything; so I cant hang a factory off a method.

           Resource indoorArenaOpenStatus;
           @Factory (value="indoorArenaOpenStatus")
           public void initIndoorArenaStatus() {
                log.info (">initIndoorArenaStatus");
                indoorArenaOpenStatus = getResource(ResourceKind.INDOOR_ARENA);