I am writing a J2SE application (without a corporate container) that uses JPA to save. Here is my persistence.xml :
<persistence 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_2_0.xsd" version="2.0"> <persistence-unit name="dbstats"> <class>dreambear.stats.data.GamePlayedEvent</class> <class>dreambear.stats.data.HyveMemberCountPoll</class> <class>dreambear.stats.data.ProfileCountPoll</class> <class>dreambear.stats.data.UserSession</class> <class>dreambear.stats.data.UsersOnlinePoll</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> <property name="hibernate.max_fetch_depth" value="3" /> <property name="hibernate.hbm2ddl.auto" value="update" /> <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> <property name="javax.persistence.jdbc.user" value="dbstats" /> <property name="javax.persistence.jdbc.password" value="*****" /> <property name="javax.persistence.jdbc.url" value="jdbc:mysql://example.com/dbstats" /> </properties> </persistence-unit> </persistence>
This is a static file "compiled" into the application. However, I need to extract the credentials so that I can load them from the configuration parameters at runtime, because they are different for, for example. development and live version of the application.
I load the default persistence setting:
emf = Persistence.createEntityManagerFactory("dbstats");
How can I externalize credentials in this setting? I could generate a persistence.xml file at runtime, but a bit hacked.
java hibernate jpa persistence
Bart van Heukelom Dec 28 '10 at 18:24 2010-12-28 18:24
source share