10 Replies Latest reply on Mar 7, 2010 3:26 AM by Rick Kilcoyne

    Is there any way to integrate DAO layer

    Macin My Newbie

      Is there any way to integrate DAO layer with Seam.

        • 1. Re: Is there any way to integrate DAO layer
          Marco Röösli Newbie

          I use gilead. It allows to transform your entities so that you can use them as DAO Gilead

          • 2. Re: Is there any way to integrate DAO layer
            Rick Kilcoyne Newbie


            Have you ever run into any performance issues with Gilead's clone method? I ask this here (and not at gilead.com) because when profiling, RollbackInterceptor is marked as the hotspot. I'm running a clone across a set of about 100 objects using:

                      List<Message> results = (List<Message>) getBeanManager().clone(messages);

            where getBeanManager() is defined in the same SLSB class as:

                 private PersistentBeanManager getBeanManager() {
                      PersistentBeanManager beanManager = PersistentBeanManager.getInstance();
                      HibernateUtil hibernateUtil = new HibernateUtil();
                                ((HibernateSessionProxy) entityManager.getDelegate()).getSessionFactory());
                      beanManager.setProxyStore(new StatelessProxyStore());
                      return PersistentBeanManager.getInstance();

            First 10 runs or so are fine. After that, the speed quadruples and never recovers. It almost seems as if the system starts to garbage collect after every object clone operation, because the results are as expected, they just become VERY slow.

            Any help would be much appreciated.


            • 3. Re: Is there any way to integrate DAO layer
              Rick Kilcoyne Newbie

              BTW, entityManager is inject like:

                   @In EntityManager entityManager;


              • 4. Re: Is there any way to integrate DAO layer
                Rick Kilcoyne Newbie

                Figured it out.

                By default the StatelessProxyStore spins off a separate thread to handle the serialization. This was causing problems with my server. It can be easily disabled as seen below.

                The working code:

                     private PersistentBeanManager getBeanManager() {
                          PersistentBeanManager beanManager = new PersistentBeanManager();
                          HibernateUtil hibernateUtil = new HibernateUtil();
                                    ((HibernateSessionProxy) em.getDelegate()).getSessionFactory());
                          StatelessProxyStore slps = new StatelessProxyStore();
                          return beanManager;

                • 5. Re: Is there any way to integrate DAO layer
                  Rick Kilcoyne Newbie

                  Here's my Seam component used to provide a Gilead persistent bean manager to other components. Hope someone can find this useful:

                  package com.myproject.seam;
                  import java.io.Serializable;
                  import javax.persistence.EntityManager;
                  import javax.transaction.Synchronization;
                  import net.sf.gilead.core.PersistentBeanManager;
                  import net.sf.gilead.core.hibernate.HibernateUtil;
                  import net.sf.gilead.core.store.stateless.StatelessProxyStore;
                  import org.jboss.seam.ScopeType;
                  import org.jboss.seam.annotations.Create;
                  import org.jboss.seam.annotations.Install;
                  import org.jboss.seam.annotations.Name;
                  import org.jboss.seam.annotations.Scope;
                  import org.jboss.seam.annotations.TransactionPropagationType;
                  import org.jboss.seam.annotations.Transactional;
                  import org.jboss.seam.annotations.Unwrap;
                  import org.jboss.seam.annotations.intercept.BypassInterceptors;
                  import org.jboss.seam.persistence.HibernateSessionProxy;
                  public class GileadHibernateUtil implements Serializable, Synchronization {
                       private static final long serialVersionUID = 27L;
                       private transient EntityManager _emp;
                       public void setEntityManager(EntityManager entityManager) {
                            _emp = entityManager;
                       public void create() {
                            PersistentBeanManager beanManager = PersistentBeanManager.getInstance();
                            HibernateUtil hibernateUtil = new HibernateUtil();
                                      ((HibernateSessionProxy) _emp.getDelegate()).getSessionFactory());
                            StatelessProxyStore proxyStore = new StatelessProxyStore();
                       public PersistentBeanManager getBeanManager() {
                            return PersistentBeanManager.getInstance();
                       public void afterCompletion(int status) {
                       public void beforeCompletion() {}

                  It's configured in components.xml like:

                     <property name="entityManager">#{entityManager}</property>

                  Now in your components you can use the beanManager:

                  public class WidgetService {
                      @In EntityManager entityManager;
                      @In PersistentBeanManager beanManager;
                      public List<Widget> fetchWidgets() {
                          String qlString = "SELECT w FROM Widget";
                          Query qry = entityManager.createQuery(qlString);
                          List<Widget> widgets = qry.getResultList();
                          List<Widget> results = (List<Widget>) beanManager.clone(widgets);
                          return results;

                  • 6. Re: Is there any way to integrate DAO layer
                    Johannes Hollerer Newbie

                    Hi Rick,

                    Thanks for the nice class - it helps to start but i am still confused regarding the gilead documentation and samples in correspondance with the SEAM setup for GWT RPC's !

                    I want to use GWT as a front end of my Seam server!

                    Is this the correct setup ??

                    • 1) I create the Hibernate Pojo's

                    • 2) The Pojo's need to extends LightEntity (they still have all the Annotations - right)

                    • 3) I create a interface public interface MyService extends RemoteService with the @Local Annotation on the SEAM side

                    • 4) I make the implemenation of that Service with the @Name(package.path.to.MyService) showing the full path (for GWT) Question??:Why is your WidgetService class not an @WebRemote - how will this call then work ??

                    • 5) I share the Pojo's between the GWT client and the SEAM server (how does this work with the Hibernate Annotations - the GWT Client cant use that ??)

                    • 6) In the GWT client i add the Annotation @RemoteServiceRelativePath(????) (what should be in there)

                    • 7) Now i initialize the RPC (like in the SEAM docu) GWT.create(MyService.class)

                    • 9) I set the service endpoint in GWT

                    • 8) Then i call the function (getAll()) - and get the DTO's ??

                    • 9) And with the actual version 1.3 i can make a lazy loading of the object ??

                    Can you help me out if this setup is correct as i think i miss a point - it does not seem to work ???

                    many thanks


                    • 7. Re: Is there any way to integrate DAO layer
                      Humberto Franco Newbie

                      I tried your implementation the way you posted it but when I try to run the application i get the following error:

                      Could not create Component: beanManager
                           at ...... 
                      Caused by: java.lang.NoClassDefFoundError: net/sf/gilead/core/IPersistenceUtil
                           at java.lang.Class.getDeclaredMethods0(Native Method)
                           at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
                           at java.lang.Class.privateGetPublicMethods(Class.java:2547)
                           at java.lang.Class.getMethods(Class.java:1410)
                           at org.jboss.seam.Component.hasAnnotation(Component.java:1158)
                           at org.jboss.seam.Component.<init>(Component.java:218)
                           at org.jboss.seam.Component.<init>(Component.java:205)
                           at org.jboss.seam.init.Initialization.addComponent(Initialization.java:1186)
                           ... 73 more
                      Caused by: java.lang.ClassNotFoundException: net.sf.gilead.core.IPersistenceUtil 

                      Thanks for the help.

                      • 8. Re: Is there any way to integrate DAO layer
                        Johannes Hollerer Newbie

                        Be shure you have all those libraries included:

                        • 9. Re: Is there any way to integrate DAO layer
                          Humberto Franco Newbie

                          Here are only libs that I'm referencing that are different: slf4j-api-1.5.10 and slf4j-jdk14-1.5.10.  I'll switch them back to the 1.5.8 version.  Also I'm only referencing my libraries in eclipse in the edit build path option for my EJB folder, anywhere else I should reference them.  Should I also bee copying all Gilead and supporting libs to the project?  If so were do I copy them too? I'm using an EAR package. Thanks

                          • 10. Re: Is there any way to integrate DAO layer
                            Rick Kilcoyne Newbie

                            Sorry so late in getting back to you.

                            You must add these jars to your EAR project by listing them in deployed-jars-ear.list:


                            Give that a try.