2 Replies Latest reply on Jan 1, 2010 10:30 AM by alex becker

    Best way to preloading second-level Cache at Applikationstart?

    alex becker Newbie

      My Environment: Seam 2.1.2GA, EJB 3.0, JPS and Hibernate.

      I have configured an EHCache 1.7.1 and looking for the best way to initialize (preloading) my cache.
      I have tried to implement my own component Cachloader.


      public class CacheLoader {
           private Log log;
           public void loadCache(){
                log.info("Starte Cacheinitialisierung");


      import de.tele.catjump.entity.Region;
      public class RegionFacadeImpl implements RegionFacade {
           @PersistenceContext(type = PersistenceContextType.EXTENDED)
           private EntityManager em;
           private Log log;
           public void preload(){
                log.info("Lade Regionen...");
                Query q = em.createQuery("select region from Region region");
                List<Region> result = (List<Region>)q.getResultList();
                for (Region region : result) {
                     log.info("loaded Region:" +region);

      Inside some SessionFaceds, i implement an @Observer('de.tele.cache.initializing') to load the Entities. Now, i get the following Exception at Applikationstart.

      Caused by: javax.naming.NameNotFoundException: RegionFacadeImpl not bound
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
           at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
           at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
           at org.jnp.server.NamingServer.lookup(NamingServer.java:396)
           at org.jnp.server.NamingServer.lookup(NamingServer.java:399)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:713)
           at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:673)
           at javax.naming.InitialContext.lookup(InitialContext.java:392)
           at org.jboss.seam.Component.instantiateSessionBean(Component.java:1400)
           at org.jboss.seam.Component.instantiate(Component.java:1364)
           at org.jboss.seam.Component.newInstance(Component.java:2122)
           ... 64 more

      I think, when the event raised, my EJBs are not bound or initialized.
      So, can anybody tell me the best way to load some different Entities at the Applikationstart into my cache.
      Should i implement one Sessionbean to load different Entities into the Cache or should i raise a event and implement different Observer? Or something else?