persistence icon indicating copy to clipboard operation
persistence copied to clipboard

More static property names

Open gavinking opened this issue 3 weeks ago • 5 comments

The spec defines a large number of configuration properties, which are spread out over three different sections. In #862 I'm trying to resolve some inconsistencies between these lists. One issue that arises is what to do about these properties:

jakarta.persistence.provider
jakarta.persistence.qualifiers
jakarta.persistence.scope
jakarta.persistence.transactionType
jakarta.persistence.jtaDataSource
jakarta.persistence.nonJtaDataSource
jakarta.persistence.sharedCache.mode
jakarta.persistence.validation.mode

These are overrides for XML elements in persistence.xml, and so:

  • they don't make sense as properties in persistence.xml, nor, by extension, for use with PersistenceConfiguration, but, instead
  • they're used with Persistence.createEntityManager() when you have a pre-written persistence.xml file.

And so when we added the static property names to PersistenceConfiguration in 3.2, I left them off, with the sole exception (which I'm not inclined to regret) of jakarta.persistence.sharedCache.mode, because setting that property to NONE is just sooo useful that it seemed a mistake to leave it off.

However, thinking all this stuff through more carefully:

  • I now realize that being able to override the jta-datasource and non-jta-datasource elements is at least as useful;
  • one can even make a case thatjakarta.persistence.transactionType is useful in tests; and
  • I guess maybe if you have a persistence unit archive that's used in multiple different application, being able to specify jakarta.persistence.qualifiers and jakarta.persistence.scope externally is actually pretty nice.

So I think it makes sense to declare these properties as constants somewhere. But where?

  • They don't really belong on PersistenceConfiguration because they're not intended for use with that class.
  • The most sensible place to put them is on Persistence itself. But then it seems strange to have only these ones on Persistence. What should I do, copy all of them there, and use them by reference in PersistenceConfiguration?

I now kinda regret the decision to have put them on PersistenceConfiguration instead of Persistence in the first place. It just seemed natural at the time that properties which had to do with "configuring persistence" would go on a class called PersistenceConfiguration. Perhaps the best idea here is to just double down on that arguably bad decision.

gavinking avatar Dec 26 '25 12:12 gavinking