2

私は guice-persist を使用しています。Spring で行うように、Java プロパティ ファイルから persistence.xml ファイルにプロパティを挿入またはリゾルバする方法があるかどうかを知りたいです。例えば:

<?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>

そうでない場合、プロパティ ファイルからこのプロパティを挿入するために、guice-persist ライブラリを使用して EntityManager を構成するにはどうすればよいですか?

ありがとう!

4

1 に答える 1

3

作成時に追加のプロパティを指定できるようですJpaPersistModule:

JpaPersistModule jpa = new JpaPersistModule("myFirstJpaUnit");
jpa.properties(...);
Injector injector = Guice.createInjector(..., jpa);
于 2011-09-28T09:59:16.977 に答える