-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to create different object views for a table
PostPosted: Tue Feb 17, 2009 11:26 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Hi,

Suppose we have a table table_A and on object A mapped to that table, and imagine that the table has a large number of columns, so i want to recover a reduced version of A object with less attributes (less columns considered), say AReduced, but also keep the A object mapped to the table (i may need to get all columns). Is this possible? How can i tell hibernate which type of object to retreive? What happens with foreign keys to table_A? How is it represented in the hbm files?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 3:06 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Yes it is possible.

Hibernate doesn't restrict to map one table by only one class. you can map multiple class to single table. (which is not recommended).

So you can create two classes which mapped to same table (for you classA and classAReduce). If you map all or partial column of the table.
So if you want only some selective column in classAReduct , then map only selective column to property . like


Code:

class Student{

private String studentName; //map to student name column

private String fatherName; //map to father name column
}

class StudentReduce{

private String name ; //map to student name column

//no need to map call column
}



Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 5:45 am 
Beginner
Beginner

Joined: Tue Dec 19, 2006 12:55 pm
Posts: 27
Thanks for your response,

What would happen if i need a FK from B object (mapping table_B) to table_A? In the B hbm mapping file i could make reference to only one of the objects: A or AReduced. Is that correct, isn't it?

Greets.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 6:23 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
It depends upon you, whether you want to navigate to Object A or Object AReduce form Object B.

If you want to retrieve value of all the columns form table_a then use use Object A as a property in Class B.

Really appreciated your ratting on the post.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.