-->
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.  [ 1 post ] 
Author Message
 Post subject: Return Multiple entities with different classes
PostPosted: Thu Jun 25, 2009 7:48 pm 
Newbie

Joined: Thu Jun 25, 2009 7:43 pm
Posts: 1
From the following document, i could get how to get Hibernate return Multiple entities. In this example, it's always 2 returning entity but the final result is only one class called "Night.class"

http://docs.jboss.org/hibernate/stable/ ... ery-native

I have a scenario, where for view only purposes, i need to return Multiple Non-Connected entities (different classes) using same Named Query. I tried following option.

Code:
@org.hibernate.annotations.NamedNativeQueries({
@org.hibernate.annotations.NamedNativeQuery(
name = "CustomerQuery1",
query = "SELECT tl1.srno as srno1, tl1.date_added, st1.srno as srno2, st1.value1 " +
         "FROM custdb st1, top_list tl1  WHERE st1.personid=4 and tl1.personid=4",
resultSetMapping = "joinMapping")
})


@SqlResultSetMappings(
@SqlResultSetMapping(name = "joinMapping", entities = {
@EntityResult(entityClass = com.testdb.entb.CustDB1.class, fields = {
@FieldResult(name = "srno", column = "srno2"),
@FieldResult(name = "value1", column = "value1"),
   }),
@EntityResult(entityClass = com.testdb.entb.TopList.class, fields = {
@FieldResult(name = "srno", column = "srno1"),
@FieldResult(name = "dateAdded", column = "date_added"),
   })
   }
)
)


The above scenario did not work. Also the native query need to return only partial set of columns from each table. Not all the columns from each table. I read one possible solution is to use "Projection".

Can you please provide a example, how the mapping should like , for initializing multiple Entity classes having only partial set of columns, using Named/Native Query?

Thanks again in Advance

Edward


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

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.