> Drools doesn't handle Hibernate in anyway, we have no awareness of it.
> The exceptions indicates that you have lazy loading enabled for
> hibernate, but your session is disconnected when it tries to lazy load
> the object.

Hi,

  trouble is in ShadowProxyUtils ... it tries to clone the hibernate
  collection but in the process looses the hibernate session.

  I have solved it for myself with a simple patch that disables
  collection cloning for hibernate collections (if hibernate is on the
  classpath).

  Long term solution should probably be some kind of extension point
  where user can register custom delegate.

--
  pm

--- ./main/java/org/drools/util/ShadowProxyUtils.java    2007-08-18 
17:32:04.000000000 +0300
+++ ./fixed/java/org/drools/util/ShadowProxyUtils.java    2007-08-24 
11:18:14.000000000 +0300
@@ -36,6 +36,19 @@
     private static final Class UNMODIFIABLE_MAP        = 
Collections.unmodifiableMap( Collections.EMPTY_MAP ).getClass();
     private static final Class UNMODIFIABLE_COLLECTION = 
Collections.unmodifiableCollection( Collections.EMPTY_LIST ).getClass();
 
+    private static final Class PERSISTENT_COLLECTION;
+    
+    static {
+        Class clazz = null;
+        try {
+            clazz = 
Class.forName("org.hibernate.collection.PersistentCollection");
+        } catch(ClassNotFoundException e) {
+            // well, not everybody uses hibernate ...
+        } finally {
+            PERSISTENT_COLLECTION = clazz;
+        }
+    }
+    
     private ShadowProxyUtils() {
     }
 
@@ -57,7 +70,8 @@
             try {
                 if ( original instanceof Map && 
                      original != Collections.EMPTY_MAP && 
-                     !UNMODIFIABLE_MAP.isAssignableFrom( original.getClass() ) 
) {
+                     !UNMODIFIABLE_MAP.isAssignableFrom( original.getClass() ) 
&&
+                     (PERSISTENT_COLLECTION == null || 
!PERSISTENT_COLLECTION.isAssignableFrom( original.getClass()))) {
                     
                     /* empty and unmodifiable maps can't (and don't need to) 
be shadowed */
                     clone = original.getClass().newInstance();
@@ -66,7 +80,8 @@
                 } else if ( original instanceof Collection && 
                             original != Collections.EMPTY_LIST && 
                             original != Collections.EMPTY_SET && 
-                            !UNMODIFIABLE_COLLECTION.isAssignableFrom( 
original.getClass() ) ) {
+                            !UNMODIFIABLE_COLLECTION.isAssignableFrom( 
original.getClass() ) &&
+                            (PERSISTENT_COLLECTION == null || 
!PERSISTENT_COLLECTION.isAssignableFrom( original.getClass()))) {
                     
                     /* empty and unmodifiable collections can't (and don't 
need to) be shadowed */
                     clone = original.getClass().newInstance();
_______________________________________________
rules-users mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-users

Reply via email to