• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hierarchial query using hibernate

 
Mansi Mishra
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a query



I read that hierarchical queries like the one above are not supported by hibernate yet.
Or is there a way???

Writing an sql query would be the last resort for me....so please help me if this can be done anyway using hibernate criteria or projections.

Thanks
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well yes there is, Off the bat here we go ...
so you've got say an ASSOCIATE table which goes like this:



Run an alter table by adding foreign key constraint ... PARENT_ID references ASSOCIATE(ID). PARENT_ID for ROOT (the CEO of an organization for example, (that would be me for every organization you can imagine ).)

Now, once we are done, we do something like this on ORM end:


Then you basically map according to basic collections mapping ... and do operations ... let me know if you need more elaboration

Trilochan

Addendum:

You don't need anything extra special for this to happen from hibernate criteria, off course since you're only getting IDs, your option is to you AliasToBeanTransformer and transform your so called projection into a custom model. Good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic