persistence icon indicating copy to clipboard operation
persistence copied to clipboard

Addition of preCreate/postCreate callbacks for EntityManagerFactory

Open lukasj opened this issue 13 years ago • 6 comments
trafficstars

This would be useful hook for creation and/or modification of named queries.

lukasj avatar Dec 05 '11 22:12 lukasj

  • Issue Imported From: https://github.com/javaee/jpa-spec/issues/12
  • Original Issue Raised By:@glassfishrobot
  • Original Issue Assigned To: @ldemichiel

lukasj avatar Aug 31 '18 16:08 lukasj

@glassfishrobot Commented Reported by @ldemichiel

lukasj avatar Dec 05 '11 22:12 lukasj

@glassfishrobot Commented @ldemichiel said: We don't currently have a well-defined initialization sequence, and the EMF may be created by the container before application code gets to execute. However, a startup singleton EJB's postConstruct could be used for adding named queries, or a servlet init method.

lukasj avatar Dec 05 '11 22:12 lukasj

@glassfishrobot Commented c.beikov said: I have the feeling that #23 is also kind of related to this issue if a preCreate callback allowed for mutation of the meta- and physical model.

lukasj avatar Apr 15 '14 15:04 lukasj

@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-12

lukasj avatar May 05 '17 06:05 lukasj

So one way to do this would be an interface conceptually like Hibernate's SessionFactoryObserver which could be registered via persistence.xml or PersistenceConfiguration. That is:

public interface PersistenceUnitObserver {
    default void creating(String persistenceUnitName, Map<String,Object> properties) {}
    default void created(EntityManagerFactory factory) {}
    default void closing(EntityManagerFactory factory) {}
    default void closed(EntityManagerFactory factory) {}
}

Use of @Inject in implementations of PersistenceUnitObserver would be allowed.

[Alternatively, we could follow the pattern established by entity listeners and have @PreCreate, @PostCreate, @PreClose and @PostClose annotations. But here that seems like overkill to me.]

So, is there any support for introducing something like this? This issue has been open for 12 years, but it has no votes and little activity. I can see it being useful for frameworks which integrate with JPA.

gavinking avatar Aug 25 '23 18:08 gavinking