List Info

Thread: ShadowProxy & PersistentSet




ShadowProxy & PersistentSet
country flaguser name
United States
2008-04-22 10:58:25
Hi,

I have a big problem with shadowproxy.

All my objects are hibernate so they use PersistentSet in
their properties.
But when the shadowproxyfactory clone the PeristentSet
properties, I have
this error :

org.hibernate.LazyInitializationException: failed to lazily
initialize a
collection, no session or session was closed

I temporaly use shadowproxy=false and it's working but I'm
not sure it is a
good idea. (I try
drools.shadowProxy.Exclude=org.hibernate.collection.Persiste
ntCollection it
doesn't work because I don't use directly the class in the
working memory)

maybe somebody have a tip ?

thanks,

V.


-- 
View this message in context: http://www.nabble.com/ShadowProxy---Pe
rsistentSet-tp16824934p16824934.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: ShadowProxy & PersistentSet
country flaguser name
United States
2008-04-23 04:19:32
I think the method cloneObject 'ShadowProxyUtils' could be
improve like
follow :

   public static Object cloneObject(Object original) {
        Object clone = null;
        if ( original instanceof Cloneable ) {
            try {
                Method cloneMethod =
original.getClass().getMethod( "clone",
                                                            
       new
Class[0] );
                clone = cloneMethod.invoke( original,
                                            new Object[0]
);
            } catch ( Exception e ) {
                /* Failed to clone.  Don't worry about it,
and just return
                 * the original object. */
                clone = null;
            }
        }

        if ( clone == null ) {
            try {
                if ( original instanceof Map && 
                     original != Collections.EMPTY_MAP
&& 
                     !UNMODIFIABLE_MAP.isAssignableFrom(
original.getClass()
) ) {
                    
                    /* empty and unmodifiable maps can't
(and don't need to)
be shadowed */
                    clone =
original.getClass().newInstance();
                    ((Map) clone).putAll( (Map) original );
                    
                } else if ( original instanceof Collection
&& 
                            original !=
Collections.EMPTY_LIST && 
                            original !=
Collections.EMPTY_SET && 
                           
!UNMODIFIABLE_COLLECTION.isAssignableFrom(
original.getClass() ) ) {
                    
                    /* empty and unmodifiable collections
can't (and don't
need to) be shadowed */
                    clone =
original.getClass().newInstance();
                    ((Collection) clone).addAll(
(Collection) original );
                    
                } else if ( original.getClass().isArray() )
{
                    clone = cloneArray( original );
                }
                
            } catch ( Exception e ) {
                /* Failed to clone.  Don't worry about it,
and just return
                 * the original object. */
                clone = null;
            }
        }

        if ( clone == null ) {
            clone = original;
        }

        return clone;
    }


In this way my PersistentSet will be not clone and I will be
able to
continue to use shadow fact

What do you think about ?

V.

-- 
View this message in context: http://www.nabble.com/ShadowProxy---Pe
rsistentSet-tp16824934p16833560.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: ShadowProxy & PersistentSet
country flaguser name
United States
2008-04-28 08:59:07
I create a JIRA : http:/
/jira.jboss.com/jira/browse/JBRULES-1590

it's to complicate to me to create an unit test with a
hibernate session.

thanks,

V.


Mark Proctor wrote:
> 
> Can you open a JIRA for this? If you provide a unit
test with it, we'll 
> see if we can include this in 4.0.7. 5.0 will now have
shadow proxies 
> any more, as default.
> 
> Mark
> vdelbart wrote:
>> I think the method cloneObject 'ShadowProxyUtils'
could be improve like
>> follow :
>>
>>    public static Object cloneObject(Object
original) {
>>         Object clone = null;
>>         if ( original instanceof Cloneable ) {
>>             try {
>>                 Method cloneMethod =
original.getClass().getMethod(
>> "clone",
>>                                                    
                new
>> Class[0] );
>>                 clone = cloneMethod.invoke(
original,
>>                                             new
Object[0] );
>>             } catch ( Exception e ) {
>>                 /* Failed to clone.  Don't worry
about it, and just
>> return
>>                  * the original object. */
>>                 clone = null;
>>             }
>>         }
>>
>>         if ( clone == null ) {
>>             try {
>>                 if ( original instanceof Map
&& 
>>                      original !=
Collections.EMPTY_MAP && 
>>                     
!UNMODIFIABLE_MAP.isAssignableFrom(
>> original.getClass()
>> ) ) {
>>                     
>>                     /* empty and unmodifiable maps
can't (and don't need
>> to)
>> be shadowed */
>>                     clone =
original.getClass().newInstance();
>>                     ((Map) clone).putAll( (Map)
original );
>>                     
>>                 } else if ( original instanceof
Collection && 
>>                             original !=
Collections.EMPTY_LIST && 
>>                             original !=
Collections.EMPTY_SET && 
>>                            
!UNMODIFIABLE_COLLECTION.isAssignableFrom(
>> original.getClass() ) ) {
>>                     
>>                     /* empty and unmodifiable
collections can't (and
>> don't
>> need to) be shadowed */
>>                     clone =
original.getClass().newInstance();
>>                     ((Collection) clone).addAll(
(Collection) original );
>>                     
>>                 } else if (
original.getClass().isArray() ) {
>>                     clone = cloneArray( original
);
>>                 }
>>                 
>>             } catch ( Exception e ) {
>>                 /* Failed to clone.  Don't worry
about it, and just
>> return
>>                  * the original object. */
>>                 clone = null;
>>             }
>>         }
>>
>>         if ( clone == null ) {
>>             clone = original;
>>         }
>>
>>         return clone;
>>     }
>>
>>
>> In this way my PersistentSet will be not clone and
I will be able to
>> continue to use shadow fact
>>
>> What do you think about ?
>>
>> V.
>>
>>   
> 
> _______________________________________________
> rules-users mailing list
> rules-userslists.jboss.org
> 
https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/ShadowProxy---Pe
rsistentSet-tp16824934p16939583.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

Re: ShadowProxy & PersistentSet
user name
2008-04-28 09:13:32
Mock classes?

vdelbart wrote:
talk.nabble.com" type="cite">
I create a JIRA : http://jira.jboss.com/jira/browse/JBRULES-1590

it's to complicate to me to create an unit test with a hibernate session.

thanks,

V.


Mark Proctor wrote:
  
Can you open a JIRA for this? If you provide a unit test with it, we'll 
see if we can include this in 4.0.7. 5.0 will now have shadow proxies 
any more, as default.

Mark
vdelbart wrote:
    
I think the method cloneObject 'ShadowProxyUtils' could be improve like
follow :

   public static Object cloneObject(Object original) {
        Object clone = null;
        if ( original instanceof Cloneable ) {
            try {
                Method cloneMethod = original.getClass().getMethod(
"clone",
                                                                    new
Class[0] );
                clone = cloneMethod.invoke( original,

                                            new Object[0] );
            } catch ( Exception e ) {
                /* Failed to clone.  Don't worry about it, and just
return
                 * the original object. */
                clone = null;
            }
        }

        if ( clone == null ) {
            try {
                if ( original instanceof Map && 
                     original != Collections.EMPTY_MAP && 
                     !UNMODIFIABLE_MAP.isAssignableFrom(
original.getClass()
) ) {
                    
                    /* empty and unmodifiable maps can't (and don't need
to)

be shadowed */
                    clone = original.getClass().newInstance();
                    ((Map) clone).putAll( (Map) original );
                    
                } else if ( original instanceof Collection && 
                            original != Collections.EMPTY_LIST && 
                            original != Collections.EMPTY_SET && 
                            !UNMODIFIABLE_COLLECTION.isAssignableFrom(

original.getClass() ) ) {
                    
                    /* empty and unmodifiable collections can't (and
don't
need to) be shadowed */
                    clone = original.getClass().newInstance();
                    ((Collection) clone).addAll( (Collection) original );
                    
                } else if ( original.getClass().isArray() ) {
                    clone = cloneArray( original );
                }
                
            } catch ( Exception e ) {
                /* Failed to clone.  Don't worry about it, and just
return
                 * the original object. */
                clone = null;
            }
        }

        if ( clone == null ) {
            clone = original;

        }

        return clone;
    }


In this way my PersistentSet will be not clone and I will be able to
continue to use shadow fact

What do you think about ?

V.


  
      
_______________________________________________
rules-users mailing list
lists.jboss.org">rules-userslists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



    

  

Re: ShadowProxy & PersistentSet
country flaguser name
United States
2008-04-28 10:46:14
I post a test case in the JIRA


Mark Proctor wrote:
> 
> Mock classes?
> 
> vdelbart wrote:
>> I create a JIRA : http:/
/jira.jboss.com/jira/browse/JBRULES-1590
>>
>> it's to complicate to me to create an unit test
with a hibernate session.
>>
>> thanks,
>>
>> V.
>>
>>
>> Mark Proctor wrote:
>>   
>>> Can you open a JIRA for this? If you provide a
unit test with it, we'll 
>>> see if we can include this in 4.0.7. 5.0 will
now have shadow proxies 
>>> any more, as default.
>>>
>>> Mark
>>> vdelbart wrote:
>>>     
>>>> I think the method cloneObject
'ShadowProxyUtils' could be improve like
>>>> follow :
>>>>
>>>>    public static Object cloneObject(Object
original) {
>>>>         Object clone = null;
>>>>         if ( original instanceof Cloneable
) {
>>>>             try {
>>>>                 Method cloneMethod =
original.getClass().getMethod(
>>>> "clone",
>>>>                                            
                        new
>>>> Class[0] );
>>>>                 clone = cloneMethod.invoke(
original,
>>>>                                            
new Object[0] );
>>>>             } catch ( Exception e ) {
>>>>                 /* Failed to clone.  Don't
worry about it, and just
>>>> return
>>>>                  * the original object. */
>>>>                 clone = null;
>>>>             }
>>>>         }
>>>>
>>>>         if ( clone == null ) {
>>>>             try {
>>>>                 if ( original instanceof
Map && 
>>>>                      original !=
Collections.EMPTY_MAP && 
>>>>                     
!UNMODIFIABLE_MAP.isAssignableFrom(
>>>> original.getClass()
>>>> ) ) {
>>>>                     
>>>>                     /* empty and
unmodifiable maps can't (and don't
>>>> need
>>>> to)
>>>> be shadowed */
>>>>                     clone =
original.getClass().newInstance();
>>>>                     ((Map) clone).putAll(
(Map) original );
>>>>                     
>>>>                 } else if ( original
instanceof Collection && 
>>>>                             original !=
Collections.EMPTY_LIST && 
>>>>                             original !=
Collections.EMPTY_SET && 
>>>>                            
!UNMODIFIABLE_COLLECTION.isAssignableFrom(
>>>> original.getClass() ) ) {
>>>>                     
>>>>                     /* empty and
unmodifiable collections can't (and
>>>> don't
>>>> need to) be shadowed */
>>>>                     clone =
original.getClass().newInstance();
>>>>                     ((Collection)
clone).addAll( (Collection) original
>>>> );
>>>>                     
>>>>                 } else if (
original.getClass().isArray() ) {
>>>>                     clone = cloneArray(
original );
>>>>                 }
>>>>                 
>>>>             } catch ( Exception e ) {
>>>>                 /* Failed to clone.  Don't
worry about it, and just
>>>> return
>>>>                  * the original object. */
>>>>                 clone = null;
>>>>             }
>>>>         }
>>>>
>>>>         if ( clone == null ) {
>>>>             clone = original;
>>>>         }
>>>>
>>>>         return clone;
>>>>     }
>>>>
>>>>
>>>> In this way my PersistentSet will be not
clone and I will be able to
>>>> continue to use shadow fact
>>>>
>>>> What do you think about ?
>>>>
>>>> V.
>>>>
>>>>   
>>>>       
>>>
_______________________________________________
>>> rules-users mailing list
>>> rules-userslists.jboss.org
>>> 
https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>>     
>>
>>   
> 
> 
> _______________________________________________
> rules-users mailing list
> rules-userslists.jboss.org
> 
https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: http://www.nabble.com/ShadowProxy---Pe
rsistentSet-tp16824934p16941799.html
Sent from the drools - user mailing list archive at
Nabble.com.

_______________________________________________
rules-users mailing list
rules-userslists.jboss.org

https://lists.jboss.org/mailman/listinfo/rules-users

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )