M.Hussaini
M.Hussaini

Reputation: 135

No-Connection remote MySQL Connection With JPA EclipseLink

I am working on a desktop app with JPA(Eclipselink) and a remote mysql database directly.

My persistence.xml i have two PersistenceUnit one uses localhost the other uses my remote database. When i try to load EntityManagerFactory, it works fine on localhost but never gets connected to the remote and no error is provided just a very long wait. Here is part of my persistence.xml

REMOTE MYSQL ON Windows Server 2003.

<persistence-unit name="SOFALEnterprisePU3" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://192.168.10.138:3306/sofaldb"/>
  <property name="javax.persistence.jdbc.password" value="password"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
</properties>

LOCAL MYSQL

<persistence-unit name="SOFALEnterprisePU2" transaction-type="RESOURCE_LOCAL">
<properties>
  <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/sofaldb"/>
  <property name="javax.persistence.jdbc.password" value="password"/>
  <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
  <property name="javax.persistence.jdbc.user" value="root"/>
</properties>

Upvotes: 2

Views: 1754

Answers (2)

Sai Ye Yan Naing Aye
Sai Ye Yan Naing Aye

Reputation: 6738

In normal JPA, it uses only one persistence.xml per project.But you can try Spring's JPA that can use multiple persistence.xml in one project.See this link to deal with multiple persistence units.

Upvotes: 0

Eelke
Eelke

Reputation: 22013

When you say remote do you mean the same LAN or accross the internet? Cause the IP 192.168.10.138 designates a private LAN so your remote machine has to have an address on the same network like 192.168.10.*

First make sure to open port 3306 in your windows firewall.

If it is a different network, your router(s) will need to be configured to forward the port and you will have to connect to the public IP of the router.

If it is the same LAN then mysql might not have been setup to accept remote connections for that user name password combination.

Upvotes: 2

Related Questions