Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
titlepersistence.xml
<persistence>
  <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.max_fetch_depth" value="3"/>
    </properties>
  </persistence-unit>
</persistence>

You can override and add persistence unit properties in your test case:. There are currently no facilities for removing them (if you have a need for that let us know – it hasn't really come up so far).

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

p.put("movie-unit.hibernate.hbm2ddl.auto", "update");
p.put("movie-unit.hibernate.dialect", "org.hibernate.dialect.HSQLDialect");

context = new InitialContext(p);

The overriding order is as follows: 1 = highest, 4 = lowest.

  1. InitialContext properties
  2. jndi.properties from the classpath
  3. System properties
  4. persistence.xml properties

By default there are no overrides in 1-3, so #4 is the only source of information.

In the above example there would be exactly three properties for the "movie-unit" persistence unit:

  • hibernate.hbm2ddl.auto = update
  • hibernate.max_fetch_depth = 3
  • hibernate.dialect = org.hibernate.dialect.HSQLDialect

These properties would be passed by OpenEJB directly to the persistence provider (in this case Hibernate). With one exception OpenEJB does not understand or modify these properties. Details on that one exception below.

No need to specify a "transaction lookup" property

All vendors have such a property for getting a reference to the container's TransactionManager and nothing works if this is not set correctly to the OpenEJB specific class, so . To make the lives of users easier, OpenEJB will take the liberty of setting it for you.

...