[jbossseam-issues] [JBoss JIRA] Commented: (JBSEAM-3028) add ContainerManagedPersistenceContext

Julien Kronegg (JIRA) jira-events at lists.jboss.org
Wed Feb 25 07:42:44 EST 2009

    [ https://jira.jboss.org/jira/browse/JBSEAM-3028?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12454202#action_12454202 ] 

Julien Kronegg commented on JBSEAM-3028:

I think the main problem is that the container always loads the persistence.xml file (AFAIK in Jboss AS and in Websphere), see Dan's post: http://lists.jboss.org/pipermail/seam-dev/2008-December/000944.html

I wanted the other way round: keep Seam managing persistence unit and tell the container not to load the persistence units (this can be usefull to make lazy migration e.g. Seam 2.0.0.GA with POJO from WAS 6.1 to WAS 7.0). I have 5 persistence units defined in the persistence.xml and I do not want the container to load all of them at startup, when Seam can load them lazily using the <persistence:entity-manager-factory startup="false" .../>

To avoid the container to load the persistence.xml file automatically when the application starts, Dan suggests in another post to rename the file, see http://www.manning-sandbox.com/thread.jspa?messageID=78228 . This works maybe with Spring, but Seam's components.xml does AFAIK not provide a way to specify another file name than the default persistence.xml file.

I'm using another method which allows preventing the container to load all mappings by giving it an empty EntityManagerFactory:

 1. write a new PersistenceProvider:

      package x;
      public class NoJeePersistenceProvider extends HibernatePersistence {
        // called by Seam
        public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map overridenProperties) {
          // rewrap me as an HibernatePersistence
          overridenProperties.put(HibernatePersistence.PROVIDER, HibernatePersistence.class.getName());
          super.createEntityManagerFactory(persistenceUnitName, overridenProperties);

        // called by the JEE container
        public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map overridenProperties) {
          // return an empty EntityManagerFactory which does not load entity mappings
          return new EntityManagerFactory() {
            public void close() {}
            public EntityManager createEntityManager() { return null; }
            public EntityManager createEntityManager(Map m) { return null; }
            public boolean isOpen() { return false; }

 2. change the persistence unit's provider class in persistence.xml (instead of org.hibernate.ejb.HibernatePersistence):

 3. add a "/META-INF/services/javax.persistence.spi.PersistenceProvider" file having the following content:


This makes the job but is not very elegant.

Maybe a LazyHibernatePersistence factory would be better: such PersistenceProvider would keep the persistence unit parameters in its properties until the first EntityManager is requested. When requested, the entity mappings will be done. Thus, if the persistence units (lazily) loaded by the container are never used, they do not have a big impact on application startup time and memory usage.
I agree that would be a job for the Hibernate team more than for the Seam team.
Is it worth a feature request in Hibernate?

> add ContainerManagedPersistenceContext
> --------------------------------------
>                 Key: JBSEAM-3028
>                 URL: https://jira.jboss.org/jira/browse/JBSEAM-3028
>             Project: Seam
>          Issue Type: Feature Request
>          Components: Core
>    Affects Versions: 2.0.2.GA, 2.1.0.A1
>            Reporter: Dan Allen
>            Assignee: Dan Allen
>            Priority: Minor
>             Fix For: 2.1.0.GA
>         Attachments: JBSEAM-3028-v1.txt
>   Original Estimate: 2 hours
>  Remaining Estimate: 2 hours
> Perhaps this is silly, perhaps not. I have developed a wrapper around a container-managed persistence manager, avoiding the need to have to lookup the EntityManagerFactory in JNDI. The main limitation here is that you cannot use this with EJB components, so it is really just a convenience of configuration if the Java EE application server happens to offer the ability to create an EntityManager for you. This also only works with the default persistence unit.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the seam-issues mailing list