AnyDiscriminatorValue with entity in another java module


I’m migrating to hibernate 6.1.5 and I have issue with using @AnyDiscriminatorValue because a referenced entity is not in the same java module (.jar).

Is there a solution to do this?

thanking you

Either use XML mappings or add a provided/compileOnly dependency.

A priori complicated to add the dependence which is not expected in this direction.

I will try to use XML mapping with XX.hbm.xml file

Thanks to you

For information in the DTD I can’t find the tags that allow to add information related to @AnyDiscriminatorValue for example

For information, i created a integrator

I used an custom annotation for deliver unknown dependencies

The final solution with a patch when the entity is not present :

public class AnyDiscriminatorValueIntegrator implements Integrator {

  private static final Logger LOG = LoggerFactory.getLogger(AnyDiscriminatorValueIntegrator.class);

  @Override public void integrate(Metadata metadata, BootstrapContext bootstrapContext, SessionFactoryImplementor sessionFactory) {
    metadata.getEntityBindings().forEach(persistentClass -> executer(metadata, persistentClass));

  private void executer(Metadata metadata, PersistentClass persistentClass) {
    AnyDiscriminatorValueByName anyDiscriminatorValueByName = persistentClass.getMappedClass().getAnnotation(AnyDiscriminatorValueByName.class);
    if (anyDiscriminatorValueByName != null) {
      Property property = persistentClass.getProperty(anyDiscriminatorValueByName.attribut());
      if (!(property.getValue() instanceof Any annotationAny)) {
        String msgErreur = "Erreur de paramétrage de @AnyDiscriminatorValueEfluid. L'attribut %s de la classe %s n'est pas de type @Any. ".formatted(anyDiscriminatorValueByName.attribut(), persistentClass.getClassName());
        throw new AnnotationException(msgErreur);
      Map<Object, String> metaValues = annotationAny.getMetaValues();

      for (String dependance : anyDiscriminatorValueByName.dependances()) {
        if (metadata.getEntityBinding(dependance) != null) {
          metaValues.put(dependance, dependance);
        } else {
          LOG.warn("L'entité %s n'est pas connue. Normal par exemple si entité d'efluid alors que l'on lance une JVM sans efluid.".formatted(dependance));

  @Override public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    LOG.debug("Exécuté lors d'une exception");

I know it’s grubby because I modify the metamodel, but it allows to find a solution while waiting for the redesign of the model

The hbm.xml mapping is described in the old documentation: Chapter 5. Basic O/R Mapping