hibernate - 如何使用 Guice 将属性注入(inject)/解析到 XML 文件中以配置 persistence.xml 文件?

标签 hibernate configuration guice guice-persist

我正在使用 guice-persist,我想知道是否有任何可以将 Java 属性文件中的属性注入(inject)或解析器属性到 persistence.xml 文件中,就像我对 Spring 所做的那样。例如:

<?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 以便从属性文件注入(inject)此属性?

谢谢!

最佳答案

看起来您可以在创建JpaPersistModule时提供其他属性:

JpaPersistModule jpa = new JpaPersistModule("myFirstJpaUnit");
jpa.properties(...);
Injector injector = Guice.createInjector(..., jpa);

关于hibernate - 如何使用 Guice 将属性注入(inject)/解析到 XML 文件中以配置 persistence.xml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7578274/

相关文章:

linux - 如何使用 dhclient 将供应商特定选项传递到 DHCP 服务器?

java - Maven 找不到 persistence.xml

java - Guice 2.0 的 ClassNotFoundException

java - Spring 数据 : Configuring using only Java?

java - SmartGwt 和 hibernate 用于数据库连接

java - 尝试将 MySQL 服务器连接到 Spring Boot App STS 时出现多个错误

java - 如何使用 Guice 将参数传递给 Provider?

java - Hibernate 获取带有条件的相关表

asp.net-mvc - Azure 上的 Umbraco 6 : UmbracoModule Service Unavailable

python - 是否存在用于滚动日志/配置文件的 python 工具?