-->
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.  [ 6 posts ] 
Author Message
 Post subject: Flattening a table
PostPosted: Thu Jun 10, 2004 9:15 pm 
Newbie

Joined: Wed Jun 09, 2004 11:13 am
Posts: 4
I want to have a 'Customer' class that has a 'getCountryName()' property.

Basically, I have a 'Customer' table, a 'Country' table, and I can get the country name doing customer.getCountry().getName(), but I want to be able to write the following query:

"from Customer c where c.countryname = 'USA'"

so I need to map the country.Name field to customer.countryName in the mapping file, and I don't find the way to do it.

Thanks,

Peter.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 9:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why would you not write:
Code:
from Customer c where c.country.name= 'USA'


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 9:31 pm 
Newbie

Joined: Wed Jun 09, 2004 11:13 am
Posts: 4
Is not a 'real world case'. I'm trying to know if I can change my schema from being something like

Customer:
Id
CountryName

to

Customer
Id
CountryId

Country
Id
Name

and hide that change in the mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 11, 2004 12:52 pm 
Newbie

Joined: Fri Jun 11, 2004 12:41 pm
Posts: 3
You can do this sort of thing with the formula attribute of the property element.

A couple of gotchas though:
-Your rdbms needs to support subselects
- the property will be read-only

I investigated this option but couldn't use it because MySQL 4.0 does not support subselects.

search the forum for "formula subselect" for more info.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 11, 2004 8:56 pm 
Newbie

Joined: Wed Jun 09, 2004 11:13 am
Posts: 4
OK, does anybody know if supporting this is in the hibernate roadmap?

Doing a subselect when you can do a simple join is not something I want to do as a general solution, even if I can apply it when there are not a lot of records in the tables involved.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 11, 2004 11:00 pm 
Newbie

Joined: Fri Jun 11, 2004 12:41 pm
Posts: 3
This appears to be slated for hibernate3: http://www.hibernate.org/200.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.