Skip to content

Infer Security JPA persistence unit based on the @UserDefinition entity persistence unit #51480

@michalvavrik

Description

@michalvavrik

Description

Working on #51279, I keep running into the fact that currently, each Hibernate entity which serves in the Security JPA as the @UserDefinition has predetermined persistence unit based on the package it belongs to. So to my understanding, Hibernate persistence units either have explicitly declared package, or there is just one active persistence unit and from that and the entity package, we can figure which persistence unit to use in case the entity is mapped just to one.

Thus, IMO we can:

  • do not require quarkus.security-jpa.persistence-unit-name for most cases and just select the persistence unit for users automatically unless one entity is mapped to multiple PUs. In which case, how is it useful to users when we only allow one PU for the user definition entity?
  • support named persistence units for Hibernate Reactive (I mean in quarkus-security-jpa-reactive) as well, since we will know the PU name and it is just about the right io.quarkus.hibernate.orm.PersistenceUnit injection point qualifier for our session factory

Implementation ideas

I'd have to look into Hibernate internals and see how to get this mapping between entity and persistence unit, but I believe they must have this mapping somewhere. It is only lately when Hibernate was allowed to be started without any entity. Maybe @yrodiere @marko-bekhta or @lucamolteni can give us a hint. Otherwise, we can just figure it out from the code, no problem.

also cc @FroMage since it is about the Security JPA

Metadata

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