[seam-commits] Seam SVN: r13666 - branches/community/Seam_2_2/src/main/org/jboss/seam/persistence.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Mon Aug 30 09:53:43 EDT 2010


Author: epbernard
Date: 2010-08-30 09:53:42 -0400 (Mon, 30 Aug 2010)
New Revision: 13666

Modified:
   branches/community/Seam_2_2/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
Log:
JBSEAM-4649 JBSEAM-4700 Fix issues with Hibernate Search 3.2 and AS 6 (incorrect discovery sequence and double proxying leading to exceptions)

Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2010-08-30 09:35:25 UTC (rev 13665)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/persistence/HibernatePersistenceProvider.java	2010-08-30 13:53:42 UTC (rev 13666)
@@ -53,44 +53,49 @@
    private static Method FULL_TEXT_ENTITYMANAGER_CONSTRUCTOR;
    static
    {
-      try
+      boolean hibernateSearchPresent = false;
+      try 
       {
-         String version = null;
-         try {
-            Class searchVersionClass = Class.forName("org.hibernate.search.Version");
-            Field versionField = searchVersionClass.getDeclaredField("VERSION");
-            version = (String) versionField.get(null);
-         }
-         catch (Exception e)
+         Class.forName("org.hibernate.search.Version");
+         hibernateSearchPresent = true;
+      }
+      catch (Exception e)
+      {
+         log.debug("Hibernate Search not present", e);
+      }
+      if (hibernateSearchPresent) 
+      {
+         try 
          {
-            log.debug("no Hibernate Search, sorry :-(", e);
-         }
-         if (version != null) {
             Class searchClass = Class.forName("org.hibernate.search.Search");
-            try {
+            try 
+            {
                FULL_TEXT_SESSION_CONSTRUCTOR = searchClass.getDeclaredMethod("getFullTextSession", Session.class);
             }
-            catch (NoSuchMethodException noSuchMethod) {
+            catch (NoSuchMethodException noSuchMethod) 
+            {
                log.debug("org.hibernate.search.Search.getFullTextSession(Session) not found, trying deprecated method name createFullTextSession");
                FULL_TEXT_SESSION_CONSTRUCTOR = searchClass.getDeclaredMethod("createFullTextSession", Session.class);
             }
             FULL_TEXT_SESSION_PROXY_CLASS = Class.forName("org.jboss.seam.persistence.FullTextHibernateSessionProxy");
             Class jpaSearchClass = Class.forName("org.hibernate.search.jpa.Search");
-            try {
+            try 
+            {
                FULL_TEXT_ENTITYMANAGER_CONSTRUCTOR = jpaSearchClass.getDeclaredMethod("getFullTextEntityManager", EntityManager.class);   
             }
-            catch (NoSuchMethodException noSuchMethod) {
+            catch (NoSuchMethodException noSuchMethod) 
+            {
                log.debug("org.hibernate.search.jpa.getFullTextSession(EntityManager) not found, trying deprecated method name createFullTextEntityManager");
                FULL_TEXT_ENTITYMANAGER_CONSTRUCTOR = jpaSearchClass.getDeclaredMethod("createFullTextEntityManager", EntityManager.class);
             }
             FULL_TEXT_ENTITYMANAGER_PROXY_CLASS = Class.forName("org.jboss.seam.persistence.FullTextEntityManagerProxy");
             log.debug("Hibernate Search is available :-)");
          }
-      }
-      catch (Exception e)
-      {
-         log.debug("no Hibernate Search, sorry :-(", e);
-      }
+         catch (Exception e)
+         {
+            log.debug("Unable to load Hibernate Search for ORM", e);
+         }
+      }    
    }
 
    @Override
@@ -109,22 +114,42 @@
    {
       if (FULL_TEXT_SESSION_PROXY_CLASS==null)
       {
-         return (Session) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
-               new Class[] { HibernateSessionProxy.class },
-               new HibernateSessionInvocationHandler(session));
+         if ( session instanceof HibernateSessionProxy )
+         {
+            return session;
+         }
+         else 
+         {  
+            return (Session) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+                  new Class[] { HibernateSessionProxy.class },
+                  new HibernateSessionInvocationHandler(session));
+         }
       }
       else
       {
-         try {
-            return (Session) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
-                  new Class[] { FULL_TEXT_SESSION_PROXY_CLASS },
-                  new HibernateSessionInvocationHandler((Session) FULL_TEXT_SESSION_CONSTRUCTOR.invoke(null, session)));
+         try 
+         {
+            if ( FULL_TEXT_SESSION_PROXY_CLASS.isAssignableFrom( session.getClass() ) )
+            {
+               return session;
+            }
+            else {
+               return (Session) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+                     new Class[] { FULL_TEXT_SESSION_PROXY_CLASS },
+                     new HibernateSessionInvocationHandler((Session) FULL_TEXT_SESSION_CONSTRUCTOR.invoke(null, session)));
+            }
          }
          catch(Exception e) {
             log.warn("Unable to wrap into a FullTextSessionProxy, regular SessionProxy returned", e);
-            return (Session) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
-                  new Class[] { HibernateSessionProxy.class },
-                  new HibernateSessionInvocationHandler(session));
+            if ( session instanceof HibernateSessionProxy ) 
+            {
+               return session;
+            }
+            else {
+               return (Session) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
+                     new Class[] { HibernateSessionProxy.class },
+                     new HibernateSessionInvocationHandler(session));
+            }
          }
       }
    }
@@ -241,12 +266,15 @@
          org.hibernate.Filter filter = getSession(entityManager).enableFilter( f.getName() );
          for ( Map.Entry<String, ValueExpression> me: f.getParameters().entrySet() )
          {
-		   Object filterValue = me.getValue().getValue();
-		   if ( filterValue instanceof Collection ) {
-		      filter.setParameterList(me.getKey(), (Collection) filterValue);
-		   } else {
-			  filter.setParameter(me.getKey(), filterValue);
-		   }
+            Object filterValue = me.getValue().getValue();
+            if ( filterValue instanceof Collection ) 
+            {
+               filter.setParameterList(me.getKey(), (Collection) filterValue);
+            } 
+            else 
+            {
+               filter.setParameter(me.getKey(), filterValue);
+            }
          }
          filter.validate();
       }



More information about the seam-commits mailing list