Hi all,
I'm newish to Spring/Hibernate (haven't used it in 2 years anyway) and I'm trying to change an existing app to work with an Oracle database that uses VPD (virual private database). Basically: the app serves several different customers and I wanted it to work like this:
1. Customer request comes in via web service.
2. Initial validation done on request, get customer id.
3. Set session context in db using customer id (this is done by calling a stored procedure our dba set up via org.springframework.jdbc.object.StoredProcedure).
4. Make DAO calls and do db stuff (the daos can only see the "current" customer).
Now, I have all this working ... kind of. When our QA got ahold of it they found that sometimes the request wouldn't find the customer data ... I assume this is due to the session context not being set for the session the daos are using.
I'm using dependency injection with a session factory that looks like this:
Code:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="PayerHostingDataSource" />
</property>
...
Sooooo, here's what the code looks like:
Code:
setSessionDao.setSession(id, "S");
which looks like:
Code:
public String setSession(String entityID, String idType)
{
CallSetSession proc = new CallSetSession(dataSource);
proc.execute(entityID, idType);
return "";
}
public class CallSetSession extends StoredProcedure {
private static final String STORED_PROC_NAME = "SP_NAME";
public CallSetSession(DataSource ds) {
super(ds, STORED_PROC_NAME);
declareParameter(new SqlParameter("P_ENTITY_ID", Types.VARCHAR));
declareParameter(new SqlParameter("P_ID_TYPE", Types.VARCHAR));
compile();
}
public String execute(String entityID, String idType) {
Map inParams = new HashMap(2);
inParams.put("P_ENTITY_ID", entityID);
inParams.put("P_ID_TYPE", idType);
Map outParams = execute(inParams);
}
}
So after I call setSession: I proceed to make dao calls from the same parent class (all injected with the same session factory) which access that customer's data ... usually =(.
EG:
Code:
customerDAO.getLocation(locationId);
customerDAO.getOtherStuff(stuff);
Here's what I'm using:
- Using hibernate 3.2.5
- C3p0 0.9.0.4
- Spring 2.5.2
- Spring-Hibernate 3.2.0.8
So questions:
1. Is there a way to log which session is being used by each component?
2. How can I get the session I use to make the setSession call to be used for all the other calls (thus scoping the data to only that customer).
3. What's the best/easiest way to achieve this with minimal code change?