2

I'm using guice-persist and I would like to know if there is any to inject or resolver properties from a Java property file into the persistence.xml file like I would do with Spring. For example:

<?xml version="1.0" encoding="UTF-8" ?>
<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="WoloxShivaJPAUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.guidomb.MyClass</class>

        <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
        <properties>
            <property name="hibernate.connection.driver_class" value="${hibernate.connection.driver_class}">
            <property name="hibernate.connection.url" value="${hibernate.connection.url}">
            <property name="hibernate.connection.username" value="${hibernate.connection.username}">
            <property name="hibernate.connection.password" value="${hibernate.connection.password}">
            <property name="hibernate.dialect" value="${hibernate.dialect}">
            <property name="hibernate.id.new_generator_mappings" value="true">
            <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
        </properties>

    </persistence-unit>
</persistence>

If not how can I configure the EntityManager using the guice-persist libray so as to inject this properties from a property file?.

Thanks!

GuidoMB
  • 2,001
  • 2
  • 24
  • 38

1 Answers1

3

It looks like you can supply additional properties when creating JpaPersistModule:

JpaPersistModule jpa = new JpaPersistModule("myFirstJpaUnit");
jpa.properties(...);
Injector injector = Guice.createInjector(..., jpa);
axtavt
  • 228,184
  • 37
  • 489
  • 472