-->
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: Need help with mapping
PostPosted: Mon Jan 07, 2008 5:39 pm 
Newbie

Joined: Mon Jan 07, 2008 5:22 pm
Posts: 2
Hello,

I have User table with huge amount of fields and relations. But for display purposes usually all I need is couple of fields from User table (username, userid).

What would be a good solution to "switch" between simplified/full User objects? So if I need to display only usernames Hibernate won't load all those related tables. And if I need I can have all full Users with all relations.

I tried to create two different mappings (simple and with all relations) for one table but seems like Hibernate doesn't like that in one session.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 5:43 pm 
Newbie

Joined: Mon Jan 07, 2008 3:58 pm
Posts: 7
I believe that you have to set an entity-name for each of the mappings to be able to have multiple mappings per table.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 6:18 pm 
Newbie

Joined: Mon Jan 07, 2008 5:22 pm
Posts: 2
In the documentation it says that entity name by default equals to class name. I tried creating two different classes (User, SimpleUser) mapped to one user table. But when I try to run a simple query like

select u from SimpleUser u

It takes probably 5 minutes to run and returns an empty list. While the same query for User takes few seconds and returns correct data.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 9:14 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Yes, it is possible to have different objects in the session with the same ID, if you relate them under the form "one to one relationship on a primary key" (reference documentation 7.2.2).

Serg, in your case case I would make a class with your simplified object, with an additional property being the full object. This full-object property would be lazily associated and read only if needed.

_________________
Gonzalo Díaz


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.