4 Replies Latest reply on Jun 17, 2009 10:08 AM by sherkan777

    dynamic parameters in persistence.xml

    markwigmans
      A typical part of a persistence.xml looks like

      <persistence-unit name="db">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/dbDatasource</jta-data-source>
      <properties>
      <property name="hibernate.cache.use_second_level_cache" value="true" />
      <property name="hibernate.hbm2ddl.auto" value="update" />
      </persistence-unit>
      ..


      The question I have is, how to dynamic configure a property that is in the given file. So no hardcoded 'hibernate.hbm2ddl.auto' value 'update' but defined in an external properties file.

      Thanks in advance.
        • 1. Re: dynamic parameters in persistence.xml
          kapitanpetko

          What do you mean by dynamic? You can replace those at build/package time using Ant or Maven filtering.
          That is not completely 'dynamic', but will do if you just want different configurations (testing, release, etc.)


          HTH


          • 2. Re: dynamic parameters in persistence.xml
            markwigmans

            In my current seam application I have an external components.xml (located in jboss/server/default/conf) file to configure the application for a particular environment.
            By 'dynamic' I mean a similar configuration possibility.


            I use jboss-4.2.3-GA and seam 2.1.1-GA

            • 3. Re: dynamic parameters in persistence.xml
              kapitanpetko

              Well JPA looks for persistence.xml on the classpath, to you could probably externalize it, like you did with components.xml.
              Depending on your application structure, you may run into problems, though.


              So if have different environments, a separate build for each one would be the safest thing.

              • 4. Re: dynamic parameters in persistence.xml
                sherkan777

                Well, I think u need to create persistence class manuallly as a java class and register it.


                Here i found some example, but u need to find it in google how to create persistence provider.




                http://forums.java.net/jive/thread.jspa?threadID=61175&tstart=0