-
Notifications
You must be signed in to change notification settings - Fork 34
attempt to respecify dataSource #1303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PersistenceContext and @PersistenceUnit both inject based on the unit name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Co-authored-by: Nathan Rauh <[email protected]>
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.