-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can I use one POJO with Multiple Session Factories?
PostPosted: Wed Aug 09, 2006 5:11 pm 
Beginner
Beginner

Joined: Tue Sep 20, 2005 11:01 am
Posts: 25
I have a DB that has 2 schemas. The schemas are “structurally equivalent” and guaranteed to stay that way. One of the schemas is considered the "staging" schema and the other is considered the "master" schema. By “structurally equivalent” I mean each schema has the same number of tables with the same names, the same column names, the same constraints, etc …

When data enters the system it gets placed in the "staging" schema. Once the data is considered finalized, and deemed acceptable, it is moved to the "master" schema.

I realize it's an unusual architecture, but unfortunately I have to live with it.

I am in the process of designing the code that will access these schemas. I want to write one set of java code that will access both schemas. At runtime the correct schema will be accessed based on the user type.

My approach will be to create 2 Session Factories - one for each schema. At runtime I can decide which Session Factory to use based on the user type.

I envision code like the following:

Code:
If (adminUser) {
   hSession = HibernateUtil.getMasterSession();
} else {
   hSession = HibernateUtil.getStagingSession();
}

MyClass  myClass = (MyClass) hSession.get(MyClass.class, new Long(myClassId));

[ ... rest of code here ...]


In order for this to work I need to use one POJO (MyClass) with both Session Factories.

Can this be done? If so, how?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 3:33 am 
Newbie

Joined: Wed Aug 09, 2006 1:43 pm
Posts: 4
Location: Austria
We are using a similar approach. In our case we use JBoss AS. There simply deployed the same beans and mappings into two different HAR-Archives.

Then we only need to decide which session factory to look up in the JNDI.

Everything works fine.


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