Conversation
to reflect what we're actually doing with this in practice
f30392e to
4946f8a
Compare
|
@njr-11 could you review this one? |
| * {@code PersistenceUnit} annotation. Or, if the value does begin with | ||
| * {@code java:} and matches the name of a persistence unit reference, | ||
| * then the corresponding {@code EntityManagerFactory} obtained from JNDI | ||
| * is used. |
There was a problem hiding this comment.
I remembered why I didn't write this with the PersistenceUnit name in the first place.
I'm not aware of an API or SPI that Jakarta Persistence provides to do this given the name of a persistence unit:
* then the container-managed {@code EntityManagerFactory} for that
* persistence unit is used, obtained as if it had been injected using the
* {@code PersistenceUnit} annotation.
The closest I see is Persistence.createEntityManagerFactory(persistenceUnitName), but that is only for Java SE and also not container managed. It's also possible that there is something in Jakarta Persistence that I am overlooking.
I would also be fine with including some language for Java SE usage here.
There was a problem hiding this comment.
@PersistenceContext and @PersistenceUnit both inject based on the unit name.
There was a problem hiding this comment.
I mean, the Javadoc is super-confusing:
/**
* (Optional) The name of the persistence unit as defined
* in the {@code persistence.xml} file. If specified, the
* persistence unit for the entity manager factory that is
* accessible in JNDI must have the same name.
*/I don't know what that second sentence means. But I'm basing my assertion on the first sentence:
The name of the persistence unit as defined in the
persistence.xmlfile
There was a problem hiding this comment.
@PersistenceContextand@PersistenceUnitboth inject based on the unit name.
Right, but we have written the Data spec not to require a compile time step that generates code. I think we would need an equivalent to Persistence.createEntityManagerFactory(persistenceUnitName) for Jakarta EE usage to ensure it is always implementable.
There was a problem hiding this comment.
I think we would need an equivalent to Persistence.createEntityManagerFactory(persistenceUnitName) for Jakarta EE usage to ensure it is always implementable.
+1
Co-authored-by: Nathan Rauh <nathan.rauh@us.ibm.com>
Refinement of what was stated in #423 to reflect what we're actually doing with this in practice. Basically, say that the
dataSourcecan just be the name of a persistence unit.