views:

140

answers:

0

I have the Hibernate model:

@Cache(usage = CacheConcurrencyStrategy.NONE, region = SitesConstants.CACHE_REGION)

public class Node extends StatefulEntity implements Inheritable<Node>, Cloneable {

    private Node _parent;

    private List<Node> _childNodes;
..
}

@Cache(usage = CacheConcurrencyStrategy.NONE, region = SitesConstants.CACHE_REGION)

public class Page extends Node implements Defaultable, Securable {

    private RootZone _rootZone;

    ......

    @OneToOne(fetch = FetchType.LAZY)

    @JoinColumn(name = "root_zone_id", insertable = false, updatable = false)

    public RootZone getRootZone() {

        return _rootZone;

    }

    public void setRootZone(RootZone rootZone) {

        if (rootZone != null) {

            rootZone.setPageId(this.getId());

            _rootZone = rootZone;

        }

    }

}

I want to get all pages ( call getSiteTree), so I using this query

String hpql = "SELECT  n FROM Node n ";

See the trace I find

**Page.setRootZone(RootZone) line: 155**    
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
**BasicPropertyAccessor$BasicSetter.set(Object, Object, SessionFactoryImplementor) line: 66**   
PojoEntityTuplizer(AbstractEntityTuplizer).setPropertyValues(Object, Object[]) line: 352    
PojoEntityTuplizer.setPropertyValues(Object, Object[]) line: 232    
SingleTableEntityPersister(AbstractEntityPersister).setPropertyValues(Object, Object[], EntityMode) line: 3580  
TwoPhaseLoad.initializeEntity(Object, boolean, SessionImplementor, PreLoadEvent, PostLoadEvent) line: 152   
QueryLoader(Loader).initializeEntitiesAndCollections(List, Object, SessionImplementor, boolean) line: 877   
QueryLoader(Loader).doQuery(SessionImplementor, QueryParameters, boolean) line: 752 
QueryLoader(Loader).doQueryAndInitializeNonLazyCollections(SessionImplementor, QueryParameters, boolean) line: 259  
QueryLoader(Loader).doList(SessionImplementor, QueryParameters) line: 2232  
QueryLoader(Loader).listIgnoreQueryCache(SessionImplementor, QueryParameters) line: 2129    
QueryLoader(Loader).list(SessionImplementor, QueryParameters, Set, Type[]) line: 2124   
QueryLoader.list(SessionImplementor, QueryParameters) line: 401 
QueryTranslatorImpl.list(SessionImplementor, QueryParameters) line: 363 
HQLQueryPlan.performList(QueryParameters, SessionImplementor) line: 196 
SessionImpl.list(String, QueryParameters) line: 1149    
QueryImpl.list() line: 102  
QueryImpl.getResultList() line: 67  
NodeDaoImpl.getSiteTree(long) line: 358 
PageNodeServiceImpl.getSiteTree(long) line: 797 
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
AopUtils.invokeJoinpointUsingReflection(Object, Method, Object[]) line: 307 
JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 198   
$Proxy100.getSiteTree(long) line: not available 

The calling setRootZone in Page makes Hibernate issue a hit to database. I don't want this.

So my question is + Why query

String hpql = "SELECT  n FROM Node n ";

issues un-expected trace logs like above.

Why the query String hpql = "SELECT n.nodename FROM Node n " not?

What is the mechanism behind?

Note: I'm using hibernate caching level 2.

  • In case I don't want to see that trace logs. I mean I just get Node data only. How to do ?

Thanks for your help.