Skip to content

Custom qualifier annotations for named persistence units / datasources / etc. #42780

Open

Description

Description

The next version of JPA will allow specifying the FQN of a CDI annotation in persistence.xml, so that an EntityManager injection point can be qualified with that annotation to have specific persistence unit injected. See https://in.relation.to/2024/08/20/cdi-jpa/.

Since persistence.xml is not used much in Quarkus, and in any case discouraged in favor of application.properties, we should perhaps think of a similar feature in application.properties. And while we're at it, not limit it to

cc @gavinking

Implementation ideas

We could go with a simple transposition of the JPA feature to application.properties:

quarkus.hibernate-orm."users".qualifier=com.acme.Users
quarkus.datasource."users".qualifier=com.acme.Users

Or we could go with a (perhaps more generic) limited stereotype feature:

package com.acme;

import io.quarkus.datasource.DataSource;
import io.quarkus.hibernate.orm.PersistenceUnit;

@PersistenceUnit("users")
@DataSource("users")
@interface Users {
}

Though in that case, I don't see why we wouldn't go for full-blown stereotype support: #42488

I'm not sure what the pros and cons of each solution would be. They seem pretty similar to me, especially with Quarkus interpreting configuration at build time. The second one is perhaps a bit simpler as it only impacts one file (Users.java) as opposed to two with the first solution (Users.java + application.properties).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions