Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Choosing mapping tables at runtime
PostPosted: Tue Feb 01, 2005 11:38 am 
Newbie

Joined: Tue Feb 01, 2005 6:52 am
Posts: 2
Hello!

Is it possible to to select the table used to map a specified class at runtime? Consider this example:

A legacy database contains a number of tables for customer of different countries. The columns in the tables are identical, only the table name differs:

Code:
customer_uk
customer_de
customer_fr


and so on. I would like to use the same class to map their content:

Code:
from Customer c where c.id =: customerId


rather than

Code:
from CustomerUk c where c.id =: customerId


is this possible?


I've tried to use a combination of multiple SessionFactories and NamingStrategies to accomplish this, but it fails. (Seems like only the first instance created loads the mapping).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 01, 2005 12:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
look into Hibernate 3 and entityname.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 01, 2005 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
and btw. how would you let hibernate decide which table to go into first ?

if only one table is "active" per sessionfactory then you could just e.g. use a NamingStrategy instance to control which table is used when.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 01, 2005 1:21 pm 
Newbie

Joined: Tue Feb 01, 2005 6:52 am
Posts: 2
Quote:
if only one table is "active" per sessionfactory then you could just e.g. use a NamingStrategy instance to control which table is used when.


This indeed works. Making it work under JBoss required some really dirty code though.

It would be very flexible if the NamingStrategy could be set for each query:

Code:
session.createQuery(...)
  .setNamingStrategy(new CountryTableNamingStrategy("uk"))
  .list()


But that would ofcourse introduce some overhead.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.