On Sep 2, 2008, at 11:35 AM, Marcin Kwapisz wrote:

Thanks for the link, this post doesn't look to be able to help me with
runtime configuration of hibernate properties though, looks like its
not
possible so I will settle for seperate persistence.xml files.

[Marcin Kwapisz]
Maybe I misunderstood something. You want to set persistent.xml properties in your test code. Look carefully at setUpClass method. There are properties set for toplink JPA, but I think you can replace them with properties for hibernate easily. The only thing I don't know is which properties are more important: those placed in persistent.xml or in test code.

I think that's TopLink specific. But it's a good idea and one we've talked about in the past.

I went ahead and hacked something up here. Now you can override properties on the persistence-units just as you can override the properties of <Resource> and <Container> objects.

So with a unit like so:

  <persistence-unit name="movie-unit">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>movieDatabase</jta-data-source>
    <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>

    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.dialect" value="mysql"/>
    </properties>
  </persistence-unit>


You can override it in your test case like so:

  Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");

  p.put("movie-unit.hibernate.dialect", "hsql");

  Context context = new InitialContext(p);

So the override format is "<unitName>.<propertyName>=<valueName>"

I've uploaded new 3.1-SNAPSHOTs to the apache snapshot repo [1]. Give them a try and let us know how it goes.

-David

[1] http://people.apache.org/repo/m2-snapshot-repository/org/apache/openejb/

Reply via email to