jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gonzalo Aguilar Delgado <gagui...@aguilardelgado.com>
Subject Re: Why lazy initialization of collections only works second time it's accessed?
Date Fri, 09 Jul 2010 19:14:59 GMT


Really curious... 

Changing the line
    @Bean(converter=ParentBeanConverterImpl.class) protected
JetspeedFolder parentFolder;

to 
    @Bean(converter=ParentBeanConverterImpl.class) protected
JetspeedCMSObject parentFolder;

Worked well because all parent objects will be of type
JetspeedCMSObject. This is not really what I want but I have to move on
and later set constraints...


But as I said. I'm still curious. Why second time trying loading worked?











El vie, 09-07-2010 a las 21:07 +0200, Gonzalo Aguilar Delgado escribió:
> Hi there!
> 
> This one is good! ;D
> I have nodetypes as follows:
> 
> Hierarchy:
> 
> CMSObject
>  Hierarchy
>    Page
>    Fragment
> 
> We only create nodes of type Page and Fragment and a page can contain
> several fragments because hierarchy node specifies that one or more
> CMSObjects can be children of nodes of it. And of course nodes that
> extends it.
> 
> Well I can save a page with it's fragments. That works well. just adding
> them as childrens. That's great!
> 
> And I can retrieve the page also! Normal eh? But not! This piece of code
> fails:
> Page page = pageManager.getPage("/test002.psml");
> System.out.println("This is page " + page.getId());
> 
>  // Temp test
>  JetspeedPageImpl jspage = (JetspeedPageImpl) page;
> 
> ---->>> Here it fails: Because proxy inside the collection
>  for(Iterator<JetspeedCMSObject> it = jspage.getChildren().iterator();
> it.hasNext(); )
> {
>         JetspeedFragmentImpl child = (JetspeedFragmentImpl) it.next();
>         if(child instanceof JetspeedFragmentImpl)
>         {
>                 System.out.println("Is Fragment: " + child.getId());
>         }
> }
> 
> And it fails because the proxy fails to load childrens on first try.
> Don't know why because of log problem I have (I have open another
> thread). 
> SEE DEBUG BELOW 
> 
> Curious thing is that it tries to load two times the fragment inside the
> page. One as page and one as fragment. (Check last two lines of first
> try).
> 
> When I stop to debug before that point I can use the watch window in
> eclipse and click on the proxy that fills the collection. This causes it
> to try loading. It shows same error. But if I try a second time it
> shows. Last line with:
> "Target loaded".
> 
> So it works! But only the second time.
> 
> Mmmmmmmmm. Strange...
> 
> Any help on this?
> 
> Thank you in advance.
> ========================= NOTICE (UPDATE)===================
> I added a try like this before the sentence that fails:
>   	List<JetspeedCMSObject> child = jspage.getChildren();
>   	try
>   	{
>   		child.iterator();
>   	}catch(Exception ex)
>   	{
>   		log.debug("Exception occurred: " + ex.getMessage());
>   	}
> 
> And found a error like this one:
> 
> DEBUG
> org.apache.jetspeed.page.TestJackrabbitPageManager.testBasicGetPage(TestJackrabbitPageManager.java:216):
Exception occurred: Cannot set the field parentFolder in the class : org.apache.jetspeed.om.model.JetspeedFragmentImpl;
nested exception is java.lang.IllegalArgumentException: Cannot invoke org.apache.jetspeed.om.model.JetspeedCMSObjectImpl.setParentFolder
on bean class 'class org.apache.jetspeed.om.model.JetspeedFragmentImpl' - argument type mismatch
- had objects of type "org.apache.jetspeed.om.model.JetspeedPageImpl" but expected signature
"org.apache.jetspeed.om.model.interfaces.JetspeedFolder"
> 
> But why the second time it works?! With this try and catch everything
> works well...
> 
> ===========================================================
> 
> 
> ============================================ LOG =================
> 
> 
> DEBUG
> org.apache.jackrabbit.ocm.manager.objectconverter.impl.SimpleFieldsHelper.retrieveSimpleField(SimpleFieldsHelper.java:184):
retrieveSimpleField: Use default value from property definition for missing mapped property
j2:name of class 'org.apache.jetspeed.om.model.JetspeedPageImpl'
> DEBUG
> org.apache.jackrabbit.ocm.manager.collectionconverter.impl.NTCollectionConverterImpl.doGetCollection(NTCollectionConverterImpl.java:230):
Collection node found : /test002.psml/P-129b887435c-10000
> DEBUG
> org.apache.jackrabbit.ocm.manager.objectconverter.impl.SimpleFieldsHelper.retrieveSimpleField(SimpleFieldsHelper.java:184):
retrieveSimpleField: Use default value from property definition for missing mapped property
j2:title of class 'org.apache.jetspeed.om.model.JetspeedFragmentImpl'
> DEBUG
> org.apache.jackrabbit.ocm.manager.objectconverter.impl.SimpleFieldsHelper.retrieveSimpleField(SimpleFieldsHelper.java:184):
retrieveSimpleField: Use default value from property definition for missing mapped property
j2:name of class 'org.apache.jetspeed.om.model.JetspeedFragmentImpl'
> DEBUG
> org.apache.jackrabbit.ocm.manager.objectconverter.impl.SimpleFieldsHelper.retrieveSimpleField(SimpleFieldsHelper.java:184):
retrieveSimpleField: Use default value from property definition for missing mapped property
j2:name of class 'org.apache.jetspeed.om.model.JetspeedPageImpl'
> 
> ============= SECOND TRY WITH eclipse debugging after this it works.
> DEBUG
> org.apache.jackrabbit.ocm.manager.collectionconverter.impl.NTCollectionConverterImpl.doGetCollection(NTCollectionConverterImpl.java:230):
Collection node found : /test002.psml/P-129b887435c-10000
> DEBUG
> org.apache.jackrabbit.ocm.manager.objectconverter.impl.AbstractLazyLoader.getTarget(AbstractLazyLoader.java:59):
Target loaded
> 
> 
> 
> 
> 
> 
> 
> 


Mime
View raw message