Changing schema of ClassDescriptor in Container [message #1081718] |
Wed, 07 August 2013 11:46  |
Eclipse User |
|
|
|
I have a @PersistenceUnit/EntityManagerFactory in my Stateless EJB. I take that reference and create an EntityManger from it, where I go into the activeSession and call setTableQualifier (the db schema name) on certain class descriptors. I then ensure the EM is closed when I am done with it. I am asking, "is there a better way to do this". Am I going to incur wierdness when two user threads initialize an EM and change class descriptors at the same time?
Here is my code
public static EntityManager getEntityManager(EntityManagerFactory emf, String abpID)
{
abpID = abpID.toUpperCase();
EntityManager em = emf.createEntityManager();
Session session = ((JpaEntityManager) em.getDelegate()).getActiveSession();
Session activeSession = session.getActiveSession();
List<Class> tapClasses = Arrays.asList(TAP_CLASSES);
for (ClassDescriptor descriptor : activeSession.getDescriptors().values())
{
if (tapClasses.contains(descriptor.getJavaClass()))
{
for (DatabaseTable table : descriptor.getTables())
{
table.setTableQualifier(abpID);
}
}
}
return em;
}
ANY help is greatly appreciated.
|
|
|
|
Re: Changing schema of ClassDescriptor in Container [message #1085281 is a reply to message #1082389] |
Mon, 12 August 2013 13:55   |
Eclipse User |
|
|
|
First, thanks for the help.
But, I have some "severe" requirements, which are getting really ugly to handle in Eclipselink that should be relatively simple, I am just having loads of fun finding the "right" way to do this.
First, I am in a container using Stateless EJBs where the PersistenceContext/Unit is injected. I have to maintain transaction consistency with the container. Second, the schema (table qualifier) is not set on all entities, and I have to be able to set it "uniquely" for each user accessing the application.
What I tried to do with your code, is to set a ThreadLocal with the schema ID in the servlet, then connect to the Session bean and see the SchemaCustomizer fire and let me set the schema for THAT session. But as far as I can tell, the customizer is only firing once for eclipselink logging into the database. It never fires again until I reload the application! I am looking into the "Dynamic" classes, but I am limited to JPA1 in this container (WebLogic 10.3) so I have to be very careful that I don't grab JPA2 capabilities.
If anyone can provide some help, again, GREATLY APPRECIATED.
Thanks
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.20239 seconds