Versions Compared

Key

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

...

In the example above you can see a contribution to the EntityManagerSource service. This service is responsible for creating EntityManagerFactory to be used to create EntityManager. When the service is initialized, it parses the persistence.xml file, file if available. For any persistence unit defined in the XML descriptor an TapestryPersistenceUnitInfo is created. The TapestryPersistenceUnitInfo interface is a mutable extension of the PersistenceUnitInfo interface (defined in the JPA specification) that allows you to configure a persistence unit programmatically. After

After parsing persistence descriptor, EntityManagerSource service applies its configuration to create further persistence units and/or update the existing. The EntityManagerSource service’s The service’s configuration is a map in which persistence unit names are associated with PersistenceUnitConfigurer instances. A PersistenceUnitConfigurer is used to configure a persistence unit programmatically that has been associated with it. In the example above you can see a contribution providing a PersistenceUnitConfigurer for the unit named JTAUnit.What  

Info

Note that the TapestryPersistenceUnitInfo instance passed to the PersistenceUnitConfigurer is either empty or my contain the persistence unit metadata read from the persistence.xml file. What happens if you contribute a PersistenceUnitConfigurer for a persistence unit that has not been defined in

...

the persistence.xml file? In this case Tapestry assumes that you want to configure the persistence unit programmatically and just creates a fresh TapestryPersistenceUnitInfo and passes it to the PersistenceUnitConfigurer.

Automatically adding managed classes 

If only a single persistence unit is defined, Tapestry scans the  application-root-package.entities package. The classes in that package are automatically added as managed classes to the defined persistence unit.

If you have additional packages containing entities, you may contribute them to the JpaEntityPackageManager service configuration.

Code Block
public class AppModule {

   @Contribute(JpaEntityPackageManager.class)
   public static void providePackages(Configuration<String> configuration) {

      configuration.add("org.example.myapp.domain");

      configuration.add("com.acme.model");
   }
}

As you can see, you may add as many packages as you wish. file?