-->
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: DB Table Binding at Runtime
PostPosted: Mon Nov 24, 2003 7:11 pm 
Newbie

Joined: Mon Nov 17, 2003 7:53 pm
Posts: 15
I would like to be able to set the table name of a class object at runtime. I've gone through the hibernate source code and made some minor changes to see if this is doable. I made a few changes and as a result one can do something like this:

Configuration cfg = new Configuration();
cfg.addClass(Airline.class);
SessionFactory sessionFactory = cfg.buildSessionFactory();
Session session = sessionFactory.openSession();
SessionImpl sessionImpl = (SessionImpl) session;
EntityPersister entityPersister = (EntityPersister)((BatcherImpl)sessionImpl .getBatcher()).getFactory().getPersister("com.sample.Airline");
//in the Airline hbm file, Airline is persisted to a table called


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2003 9:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Don't do this it is very non-threadsafe.

It is more acceptable to manipulate the object returned by Configuration.getClassMapping() and have multiple SessionFactories.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:44 am 
Newbie

Joined: Mon Nov 17, 2003 7:53 pm
Posts: 15
What is the downside of using multiple session factories? Will it hog memory if you are dealing with 2000+ users at any given time. What you suggest will require that we have a new session factory for each user depending on choices they make. I imagine it will have a negative impact on overall performance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 2:53 am 
Newbie

Joined: Mon Nov 17, 2003 7:53 pm
Posts: 15
I just want to add that it is highly desirable to be able to dynamically specify a table to bind to at the session level and would love to see this feature in hibernate. I have heard that hibernate doesn't allow this for a very, very good reason but no one seems to elaborate on what that good reason is.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 8:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The good reason is performance. The ClassPersister is immutable, so that we don't need any synchronized blocks.

And yes, 2000+ session factories will hog memory and impact performance..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 8:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
p.s. you could consider writing a custom classpersister to solve your problem


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.