10 Replies Latest reply on Mar 7, 2010 3:26 AM by rkilcoyne.rkilcoyne.mac.com

    Is there any way to integrate DAO layer

    mymacin

      Is there any way to integrate DAO layer with Seam.

        • 1. Re: Is there any way to integrate DAO layer

          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
            rkilcoyne.rkilcoyne.mac.com

            Marco,


            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();
                      hibernateUtil.setSessionFactory(
                                ((HibernateSessionProxy) entityManager.getDelegate()).getSessionFactory());
            
                      beanManager.setPersistenceUtil(hibernateUtil);
                      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.


            Rick


            • 3. Re: Is there any way to integrate DAO layer
              rkilcoyne.rkilcoyne.mac.com

              BTW, entityManager is inject like:


                   @In EntityManager entityManager;
              



              Thanks!

              • 4. Re: Is there any way to integrate DAO layer
                rkilcoyne.rkilcoyne.mac.com

                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();
                          hibernateUtil.setSessionFactory(
                                    ((HibernateSessionProxy) em.getDelegate()).getSessionFactory());
                
                          beanManager.setPersistenceUtil(hibernateUtil);
                          
                          StatelessProxyStore slps = new StatelessProxyStore();
                          slps.setUseSerializationThread(false);
                          beanManager.setProxyStore(slps);
                
                          return beanManager;
                     }
                
                

                • 5. Re: Is there any way to integrate DAO layer
                  rkilcoyne.rkilcoyne.mac.com

                  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;
                  
                  @Name("gileadHibernateUtil")
                  @BypassInterceptors
                  @Scope(ScopeType.CONVERSATION)
                  @Install(false)
                  public class GileadHibernateUtil implements Serializable, Synchronization {
                  
                       private static final long serialVersionUID = 27L;
                       private transient EntityManager _emp;
                  
                       public void setEntityManager(EntityManager entityManager) {
                            _emp = entityManager;
                       }
                       
                       @Create
                       public void create() {
                            PersistentBeanManager beanManager = PersistentBeanManager.getInstance();
                            
                            HibernateUtil hibernateUtil = new HibernateUtil();
                            hibernateUtil.setSessionFactory(
                                      ((HibernateSessionProxy) _emp.getDelegate()).getSessionFactory());
                            
                            StatelessProxyStore proxyStore = new StatelessProxyStore();
                            proxyStore.setUseSerializationThread(false);
                            
                            beanManager.setPersistenceUtil(hibernateUtil);
                            beanManager.setProxyStore(proxyStore);
                       }
                       
                       @Unwrap
                       @Transactional(TransactionPropagationType.NEVER)
                       public PersistentBeanManager getBeanManager() {
                            return PersistentBeanManager.getInstance();
                       }
                  
                       public void afterCompletion(int status) {
                            _emp.close();
                       }
                  
                       public void beforeCompletion() {}
                       
                  }
                  



                  It's configured in components.xml like:


                  <component
                        auto-create="true"
                        name="beanManager"
                        class="com.myproject.seam.GileadHibernateUtil">
                     <property name="entityManager">#{entityManager}</property>
                  </component>
                  



                  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
                    jhollerer

                    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


                    johannes

                    • 7. Re: Is there any way to integrate DAO layer
                      surfer989

                      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
                        jhollerer

                        Be shure you have all those libraries included:
                        gilead-core-1.3.0.1169.jar
                        gilead4gwt-1.3.0.1169.jar
                        gilead-hibernate-1.3.0.1169.jar
                        slf4j-api-1.5.8.jar
                        slf4j-jdk14-1.5.8.jar
                        beanlib-hibernate-5.0.2beta.jar
                        beanlib-5.0.2beta.jar

                        • 9. Re: Is there any way to integrate DAO layer
                          surfer989

                          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
                            rkilcoyne.rkilcoyne.mac.com

                            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:


                            hibernate-util.jar
                            adapter-core.jar
                            beanlib-5.0.1beta.jar
                            beanlib-hibernate-5.0.1beta.jar
                            cglib-nodep.jar


                            Give that a try.