[jboss-user] [JBoss Seam] - multiple data sources

gstacey do-not-reply at jboss.com
Thu Oct 11 17:21:22 EDT 2007


A new project I am working on requires multiple data sources and switching between them programmatically.  These data sources contain the same entites, but different data.  I set up some of the basics of the project with one datasource and a managed persistence context and it works great, but I'm having trouble with the multiple sources part.  I've done a bit of searching through docs and forums, but I haven't found any answers so far.

My questions:

1) Do I need to declare a persistence unit in my persistence.xml for each of these data sources?
 In the long run I'd like to be able to add a new datasource without having to redeploy the application, so it would be nice to avoid this.

2) How can i programmatically set a managed persistence context in  a bean?
The persistence:managed-persistence-context component seems tied to a specific persistence unit via the factory jndi name in the persistence.xml.  I couldn't do simple injection then because I would be tied to that unit right?  I tried passing in an EntityManager instead of injecting it and I could retrieve data but I got 'no active transaction' errors when I actually tried to do anything, so it seems the conversation piece wasn't working.

I'm looking into overriding EntityManagerFactory to possibly create the correct Entitymanager on login (when the source is chosen) and put it into the session at that point.  Does this seem like a viable approach?

Any help appreciated.

Thanks,
Greg


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094279#4094279

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094279



More information about the jboss-user mailing list