Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Persistance external File JPA
icon3.gif  Persistance external File JPA [message #1703882] Wed, 05 August 2015 15:23 Go to next message
Frithjof Ebert is currently offline Frithjof EbertFriend
Messages: 1
Registered: August 2015
Junior Member
Hello,


I've been looking for a solution to a problem for quite some time. I'm writing a program based on data bases. I'm using JPA and in the IDE netbeans the data base is entered via meta-inf / persistance.xml.

But now I want users to be able to use their own data bases with their installations.

Currently my persistance looks like this:

 
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="-.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="-//xmlns.jcp.org/xml/ns/persistence -://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
   <persistence-unit name="SERVICE" transaction-type="RESOURCE_LOCAL">
    <provider>org. eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>source.Customers</class>
    ...
    ...
    <class>source.Memo</class>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://192.168.112.103:3306/DATABASENAME?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.user" value="DBUSER"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.password" value="PASSWORD"/>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
 </persistence>


But I need some possibility for the user to have a config file, which is at the same folder as the JAR to enter his data base.

Namely, username, password, data base name, data base port and server address.

How can I do that? Unfortunally, I have not found anything that worked out yet.
I'm only starting to learn...


Thanks in advace,

Regards,

Frithjof
Re: Persistance external File JPA [message #1704877 is a reply to message #1703882] Mon, 10 August 2015 11:21 Go to previous message
Reiner Lott is currently offline Reiner LottFriend
Messages: 4
Registered: August 2013
Junior Member
Hi Frithjof,

i would solve this problem for your case as follows:

1. Create a gui where the user can enter:
- his database name
- and also the other parameters which are needed "user name" and "password", ...

2. and bypass this arguments included in a map while creating the entitymanagerfactory.

EntityManagerFactory emf = Persistence.createEntityManagerFactory("SERVICE", getRuntimeConfig());

final Map<String, Object> runtimeConfig = new HashMap<String, Object>();
runtimeConfig.put("javax.persistence.jdbc.user", guiValue1);
runtimeConfig.put("javax.persistence.jdbc.password", guiValue2);


KR,
Reiner

[Updated on: Mon, 10 August 2015 11:23]

Report message to a moderator

Previous Topic:NoSuchMethodError due to EclipseLink internal weaving?
Next Topic:Issue with EclipseLink "ValidationException"
Goto Forum:
  


Current Time: Thu Apr 25 00:43:18 GMT 2024

Powered by FUDForum. Page generated in 0.05340 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top