Hi team,
I'm trying to use multiple database at the same time. How I can do It ?
My Example
1. server.properties
2. DMI Code (or Servlet):
I Can get Oracle (Default Database) Connection without any problem . But for MySQL I got an error like this :
3. My Persistence.xml
Is this correct if I have same datasource name into xml file ? or If i set different names how I can configure it in server.properties file :
Any idea ???
My Env:
1. OS : Linux OpenSuSe 11.3
2. JDK : 1.7
3. Eclipse
4. Smartgwtee-3.1.d (Eval. 03.01.2012 )
Regards,
Paata Lominadze.
I'm trying to use multiple database at the same time. How I can do It ?
My Example
1. server.properties
Code:
sql.defaultDatabase: Oracle # These are the settings for use with the Oracle database. # hostname and port where the database server is installed sql.Oracle.driver.serverName: 192.168.1.7 sql.Oracle.driver.portNumber: 1521 sql.Oracle.driver.databaseName: ORCL sql.Oracle.driver.user: info sql.Oracle.driver.password: sa sql.Mysql.database.type: mysql sql.Mysql.database.ansiMode: false sql.Mysql.driver.serverName: 192.168.1.251 sql.Mysql.driver.portNumber: 3306 sql.Mysql.driver.databaseName: asteriskcdrdb sql.Mysql.driver.user: kaxa sql.Mysql.driver.password: kaxa sql.Mysql.driver: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
2. DMI Code (or Servlet):
Code:
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); EntityManager oracleManager = null; Object transaction = null; EntityManager mysqlManager = null; Object mysqlTransaction = null; try { oracleManager = EMF.getEntityManager(); transaction = EMF.getTransaction(oracleManager); System.out.println("oracleManager = "+oracleManager); System.out.println("transaction = "+transaction); mysqlManager = EMF.getEntityManager("Mysql"); mysqlTransaction = EMF.getTransaction(mysqlManager); System.out.println("mysqlManager = "+mysqlManager); System.out.println("mysqlTransaction = "+mysqlTransaction); } catch (Exception e) { if (transaction != null) { EMF.rollbackTransaction(transaction); } if (mysqlTransaction != null) { EMF.rollbackTransaction(mysqlTransaction); } e.printStackTrace(); out.println(e.toString()); } finally { if (oracleManager != null) { EMF.returnEntityManager(oracleManager); } if (mysqlManager != null) { EMF.returnEntityManager(mysqlManager); } } }
I Can get Oracle (Default Database) Connection without any problem . But for MySQL I got an error like this :
Code:
javax.persistence.PersistenceException: Unable to initialize EMF provider: null for configuration 'Mysql' at com.isomorphic.jpa.EMF.initializeProvider(EMF.java:272) at com.isomorphic.jpa.EMF.getProvider(EMF.java:243) at com.isomorphic.jpa.EMF.getEntityManager(EMF.java:129) at com.info08.billing.callcenter.server.servlets.InitAppServlet.processRequest(InitAppServlet.java:238) at com.info08.billing.callcenter.server.servlets.InitAppServlet.doGet(InitAppServlet.java:38) at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
3. My Persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="ds" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/> <property name="hibernate.connection.username" value="info"/> <property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/> <property name="hibernate.connection.password" value="sa"/> <property name="hibernate.connection.url" value="jdbc:oracle:thin:@192.168.1.7:1521:ORCL"/> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="false"/> </properties> </persistence-unit> <persistence-unit name="ds" transaction-type="RESOURCE_LOCAL"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/> <property name="hibernate.connection.username" value="kaxa"/> <property name="hibernate.connection.password" value="kaxa"/> <property name="hibernate.connection.url" value="jdbc:mysql://192.168.1.251/asteriskcdrdb"/> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="false"/> </properties> </persistence-unit> </persistence>
Is this correct if I have same datasource name into xml file ? or If i set different names how I can configure it in server.properties file :
Code:
# Name of the datasource jpa.persistenceUnitName: ds
Any idea ???
My Env:
1. OS : Linux OpenSuSe 11.3
2. JDK : 1.7
3. Eclipse
4. Smartgwtee-3.1.d (Eval. 03.01.2012 )
Regards,
Paata Lominadze.
Comment