-->
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: is it possible to do a run-time schema mapping?
PostPosted: Sun Feb 18, 2007 6:16 am 
Newbie

Joined: Thu Feb 01, 2007 6:14 pm
Posts: 3
Hi All,

i would like to know whether it is possible to do a run-time schema mapping.

suppose that one client has a users table, which has name,email and address (which i will be using for authentication) similarly if another client has entirely different schema in which name is stored in one place and other attributes are stored in some other database.

so i would like to know how this is feasible using hibernate?

thanks in advance
bekz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:02 am 
Newbie

Joined: Sat Jun 10, 2006 7:50 pm
Posts: 4
Have you tried to use multiple session factories ? One for the source User table and one for the runtime User table.

You could follow the programmatic api found in the Hibernate manual:
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#configuration-programmatic

I have used Spring's LocalSessionFactory to read in a configuration from a set of Spring files, run SchemaExport to an in-memory String[], then use the resulting scripts to pass to my DBA to apply on a production database.

You could do something similar, in the opposite direction. See http://www.onjava.com/pub/a/onjava/2004/06/23/hibernate.html for an example program.

That is, once you run the reverse engineering tool, grab the results, save the xml file locally, load up a new SessionFactory with these new mapping files.

I do not think you could use the same session factory as the initial user table, because Hibernate validates all mapping files for referential integrity first.

There is no limit to the number of session factories you may use.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:24 am 
Newbie

Joined: Thu Feb 01, 2007 6:14 pm
Posts: 3
Hi jviolette123,

Thanks for the reply.

But my scenerio is a little bit different here. Ofcourse I will be using multiple session factories if one configures users details in one DB and user attributes in another DB.
The situation that i am having is right now something to do with some legacy database schemas(read only). In such scenerios i will not be having any write access to the database and i just require my app to retreive user level details from database.
In case i have writable access i will be exporting my schema as you have said.
So the problem is something like this,
  • If I have a POJO in place which i will be using in case i have writable access, it would be a tough job to use the same POJO for the legacy database schemas? Because creating a mapping DOM with subselect would do but it would be very tedious to maintain & create such a DOM as various clients will be having different scnerio.
  • Another option is to create mapping file/DOM at run-time using CGLIB but I would like to know what all are the performance hit due to that in case somebody has already tried this or programitically do what middlegen does. I was not able to find any docs related to this


I did lot of searching for the same but was not able to find any useful docs it would be great if someone could reply back with some relevant urls.

Thanks in advance
bekz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:30 pm 
Newbie

Joined: Sat Jun 10, 2006 7:50 pm
Posts: 4
Have you considered using
Code:
entity-name="EntityName"
in the class mapping ?

That way, you could use the same POJO class with different database mappings. One mapping would be read-only (update=false, insert=false), while another mapping would be read-write.

http://www.hibernate.org/hib_docs/v3/reference/en/html/mapping.html#mapping-declaration-class


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.