persistence
persistence copied to clipboard
Addition of preCreate/postCreate callbacks for EntityManagerFactory
This would be useful hook for creation and/or modification of named queries.
- Issue Imported From: https://github.com/javaee/jpa-spec/issues/12
- Original Issue Raised By:@glassfishrobot
- Original Issue Assigned To: @ldemichiel
@glassfishrobot Commented Reported by @ldemichiel
@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.
@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.
@glassfishrobot Commented This issue was imported from java.net JIRA JPA_SPEC-12
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.