Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Parse Multitple Entities In Hibernate NativeSQL Returned List

 
yekhon wong
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In some of the code of my application, the Native SQL is required somehow so that I could use the xpath syntax to search a XML column in our Ms SQL database. And in the Native SQL I need to return a list with multitple entities.
From the url http://docs.jboss.org/hibernate/core/3. ... l#d0e13763, I able to find a sample of adding multiple entities into a single native SQL with below code:

String sql = "SELECT ID as {c.id}, NAME as {c.name}, " +
"BIRTHDATE as {c.birthDate}, MOTHER_ID as {c.mother}, {mother.*} " +
"FROM CAT_LOG c, CAT_LOG m WHERE {c.mother} = c.ID";

List loggedCats = sess.createSQLQuery(sql)
.addEntity("cat", Cat.class)
.addEntity("mother", Cat.class).list()

However I am wondering after we get the returned list, how should we further parse the list element into entities "cat" and "mother" ?
Appreciate if somebody could gimme some guidance.
Thanks.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wont the mother id of the cat object be null for mother cat?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic