I just posted a very similar question in the EJB forum. If you don't get any response here, look over there. Hopefully someone will be able to point us in the right direction.
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?
I would put the correct EntityManagerFactory into the session scope and then keep you peristence context in the conversation scope as normal.
I'm just now revisiting this topic (got pulled onto a higher priority project), and another concept / question occurred to me.
Since the entities are the same for all the datasources do I really need multiple persistence units? i.e. the only difference is the underlying connection right? Could I just get the delegate and change the Connection object at runtime?
It seems, on the surface, like this should work... if the connection is bound to the EntityManager and it doesn't change connections and the EntityManager is bound to the Seam session then changing the connection once, when the proper source is determined should work.
Can anyone comment on the feasibility of this?
Normally you bind the connection to the PU programmatically in persistence.xml - but if your underlying JPA impl allows you to safely change the connection object then there is no problem in Seam (this isn't something offered by JPA afaik, I would ask in the Hibernate forum, assuming you use Hibernate).