2011-09-28 2 views
2

저는 guice-persist를 사용하고 있습니다. Spring과 같이 Java 속성 파일에서 persistence.xml 파일로 속성을 삽입하거나 해결할 수 있는지 알고 싶습니다. 예를 들어 :Guice로 XML 파일에 속성을 삽입/해석하여 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-영속화 libray를 사용하여 EntityManager를 구성 할 수 있습니다?

감사합니다. 추가 속성을 제공 할 수 있습니다처럼 JpaPersistModule를 만들 때

답변

3

같습니다 :

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