-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: how to implement "CONNECT BY" using hibernate
PostPosted: Mon Apr 26, 2010 5:18 am 
Newbie

Joined: Sat Apr 12, 2008 12:59 pm
Posts: 10
hihi

I want to uses ORACLE "CONNECT BY" to obtain each level of tree structure, like:

A
|-B
--|-D
|-C
--|-E

The result should be: A = 1 and B,C = 2 and D,E = 3

Do I have another options to do this?

Thanks.


Top
 Profile  
 
 Post subject: Re: how to implement "CONNECT BY" using hibernate
PostPosted: Mon Apr 26, 2010 10:08 am 
Newbie

Joined: Mon May 11, 2009 11:16 am
Posts: 13
I don't know if it possible by the original Hibernate (I use Hibernate JPA implementation) but can you create a Native query and provide the result class .

Something like this

em.createNativeQuery("Select * from table connect by prior something = someotherthing",TableEntity.class).getResultList();


Top
 Profile  
 
 Post subject: Re: how to implement "CONNECT BY" using hibernate
PostPosted: Mon Apr 26, 2010 10:53 pm 
Newbie

Joined: Sat Apr 12, 2008 12:59 pm
Posts: 10
Thank you for your reply,hannehomuth.

but when I using native query, the program throws the NullPointerException, how can I solve this problem. (the query object is NOT NULL)


Code:
Query query = entityManager.createNativeQuery("SELECT group.*,level FROM GROUP group "+
                     "WHERE GROUP_TYPE = 'ACTIVE' START WITH (PARENT_GROUP_ID IS NULL) "+
                     "CONNECT BY PARENT_GROUP_ID = PRIOR GROUP_ID",GROUP.class);

log4jLogger.info("query: "+query);

List<GROUP> groups = query.getResultList();



Result:
Code:
INFO [http-8080-2] service.GroupAction (getGroups:36) - query: org.hibernate.ejb.QueryImpl@1a5db9c

...

Caused by: java.lang.NullPointerException
    at org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:157)
    at org.hibernate.loader.DefaultEntityAliases.getSuffixedPropertyAliases(DefaultEntityAliases.java:130)
    at org.hibernate.loader.DefaultEntityAliases.<init>(DefaultEntityAliases.java:76)
    at org.hibernate.loader.ColumnEntityAliases.<init>(ColumnEntityAliases.java:40)
at org.hibernate.loader.custom.sql.SQLCustomQuery.<init>(SQLCustomQuery.java:152)
at org.hibernate.engine.query.NativeSQLQueryPlan.<init>(NativeSQLQueryPlan.java:67)
at org.hibernate.engine.query.QueryPlanCache.getNativeSQLQueryPlan(QueryPlanCache.java:136)
at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:160)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:175)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
at test.GroupAction.getGroups(GroupAction.java:38)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.