-->
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: Map one object from two tables
PostPosted: Fri Mar 19, 2004 7:37 pm 
Newbie

Joined: Fri Mar 19, 2004 7:06 pm
Posts: 6
Hibernate Version: 2.1

SITUATION: I need mapping and/or query ideas for the following scenario.

DB TABLES:
------------------------------------

Product (product_id text)

ProductName (
product_name_id int
product_id int
locale text
)

DESIRED OBJECT:
------------------------------------
class Product {
private ... productID;
private ... productName; // the name for a given locale

... getters /setters ...
}


MAPPING:
------------------------------------
How should I map the productName field within the Product class mapping so that it will only contain the name for the given locale?



If I were to do this outside of the hibernate api, I would write a query like:

...

ps = prepareStatement("
SELECT p.prodctID, pn.productName
FROM product p
INNER JOIN productName pn ON p.productID = pn.productID
WHERE p.productID = ?
AND pn.locale = ?
");

ps.setInt( 123 );
ps.setLocale( "xyz" );
ps.execute();
...

new Product( resultSet.getInt("productId", resultSet.getInt("productName"));


Any ideas would be much appreciated!

Thanks,

Tim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 11:53 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
create an updatable view and map it like any other class?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 3:59 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Apparently the ability to do this will be in the next version (2.2) of Hibernate.

See Gavin's post on this thread:
http://forum.hibernate.org/viewtopic.php?t=929150


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 22, 2004 4:10 pm 
Newbie

Joined: Fri Mar 19, 2004 7:06 pm
Posts: 6
Thanks. I've come to the realization (and I hope it's the correct realization) that I will let my application view determine which locale should be displayed. I plan to pull the data from the database using Hibernate in a 1-to-many relationship and then simply grab the right object based on the current locale of the user within the app.

I appreciate the feedback!

Thanks,
Tim


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.