[jboss-user] [JBoss Seam] - Re: Change Database Connection at Runtime
We had the same problem and never really found a solution for it. The (business/legal) requirement was to store each clients financial data in a separate DB, but have a single web application where a use can switch between different clients (depending on authorizations). We never really found a way to solve the problem. As a workaround we did what Ralph proposed and individually configured lots of datasources (one for each client, plus a couple spare ones) with generic names and access the entity manager programmatically. Besides being an ugly hack and wasting resources it does not really solve the problem the original poster is having: What do you do if the database connection details are only delivered dynamically after login? This would be dead-easy to do with JDBC, but Hibernate/JPA/Seam makes this hard to do. @bravefencer (?): Put code into code tags! View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4089606#4089606 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4089606 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [JBoss Seam] - Re: Change Database Connection at Runtime
thank you. But the problem is, that the Database Connection Information(url, password, username..) are retrievied at runtime of the application. so i can not configure a second, third.. database in a configuration file. at Application start i have the following databasase defined in JBoss-Beans.xml(i'm using tomcat 6.0 server) : http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="urn:jboss:bean-deployer bean-deployer_1_0.xsd" xmlns="urn:jboss:bean-deployer"> com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc:sqlserver://localhost:1500;databaseName=Userdatabase user user java:/ZDBsource 0 10 1000 10 This datasource will be queried to gain the Datasource Connection Information to another Database. At this point i must programatically establish the Connection to that second Database. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4089605#4089605 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4089605 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user
[jboss-user] [JBoss Seam] - Re: Change Database Connection at Runtime
Hi breaveFencer In your resources/WEB-INF/components.xml configuration file you find the following line: | | Where "yourDBname" is normaly the name of your db reference in /META-INF/persistence.xml | | org.hibernate.ejb.HibernatePersistence | java:/yourDBnameDatasource | | | | | | | | which is actually a reference to the jboss *-ds.xml configuration. You may configure a second database connection (an addition *-ds.xml, a new enty in your persitence.xml and components.xml). | | On code level you may reference the new entityManager with | entityManager= (EntityManager) Component.getInstance( "entityManager2" ); | The old one with | entityManager= (EntityManager) Component.getInstance( "entityManager" ); | | Or simply with annotation | | @In EntityManager entityManager; | Can not garantee this works but i would try it. Greetings Ralph View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4089585#4089585 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4089585 ___ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user