payintech/play-ebean

BeanNotEnhancedException if I got wide card inside enhancement array in config file

almothafar opened this issue · 4 comments

When I have models in many packages and I use the wildcard .* inside it, it seems enhancement doesn't work for those packages other than models.*, if I move everything in sub.models.* to models.* it will work without any issues.

I tried to specify alerts.models.embeddables.PreferenceId instead of wildcard and it is not working as well.

Now, the most annoying part is the issue happened only in production distributed files, in developments, there are no issues at all.

Expected behavior

To work just fine everywhere!

Actual behavior

Anything not in model,* don't work.

Steps to reproduce

@Embeddable
public class PreferenceId implements Serializable {
    @Column(name = "UserId", nullable = false, updatable = false)
    private Integer userId;

    @Column(name = "Type", length = 15, nullable = false, updatable = false)
    private AnyEnumType type;

    public PreferenceId(Integer userId, AnyEnumType type) {
        this.userId = userId;
        this.type = type;
    }

    public PreferenceId() {
    }

// .. setters and getters
}
ebean {
  servers {
    default {
      enhancement = [
        "models.*",
        "alerts.models.*"
      ]
      settings {
        allQuotedIdentifiers = true
      }
    }
  }
}

Error:

4) Error injecting constructor, io.ebean.config.BeanNotEnhancedException: Bean class alerts.models.embeddables.PreferenceId is not enhanced? Check packages specified in ebean.mf. If you are running in IDEA or Eclipse check that the enhancement plugin is installed. See https://ebean.io/docs/trouble-shooting#not-enhanced,
  at play.db.ebean.orm.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:64),
  at play.db.ebean.orm.EbeanDynamicEvolutions.class(EbeanDynamicEvolutions.java:51),
  while locating play.db.ebean.orm.EbeanDynamicEvolutions,
Caused by: io.ebean.config.BeanNotEnhancedException: Bean class alerts.models.embeddables.PreferenceId is not enhanced? Check packages specified in ebean.mf. If you are running in IDEA or Eclipse check that the enhancement plugin is installed. See https://ebean.io/docs/trouble-shooting#not-enhanced,
	at io.ebeaninternal.server.deploy.BeanDescriptorManager.setEntityBeanClass(BeanDescriptorManager.java:1408),
	at io.ebeaninternal.server.deploy.BeanDescriptorManager.createByteCode(BeanDescriptorManager.java:1293),
	at io.ebeaninternal.server.deploy.BeanDescriptorManager.readDeployAssociations(BeanDescriptorManager.java:1221),
	at io.ebeaninternal.server.deploy.BeanDescriptorManager.registerEmbeddedBean(BeanDescriptorManager.java:669),
	at io.ebeaninternal.server.deploy.BeanDescriptorManager.readEntityDeploymentInitial(BeanDescriptorManager.java:659),
	at io.ebeaninternal.server.deploy.BeanDescriptorManager.deploy(BeanDescriptorManager.java:318),
	at io.ebeaninternal.server.core.InternalConfiguration.<init>(InternalConfiguration.java:177),
	at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:110),
	at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:35),
	at io.ebean.DatabaseFactory.createInternal(DatabaseFactory.java:123),
	at io.ebean.DatabaseFactory.create(DatabaseFactory.java:77),
	at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:50),
	at play.db.ebean.orm.EbeanDynamicEvolutions.lambda$start$2(EbeanDynamicEvolutions.java:127),
	at java.base/java.util.HashMap.forEach(Unknown Source),
	at play.db.ebean.orm.EbeanDynamicEvolutions.start(EbeanDynamicEvolutions.java:123),
	at play.db.ebean.orm.EbeanDynamicEvolutions.<init>(EbeanDynamicEvolutions.java:68),
	at play.db.ebean.orm.EbeanDynamicEvolutions$$FastClassByGuice$$9cd3c635.newInstance(<generated>),
	at com.google.inject.internal.DefaultConstructionProxyFactory$FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89),
	at com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:114),
	at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:91),
	at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:306),
	at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40),
	at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:168),
	at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:39),
	at com.google.inject.internal.InternalInjectorCreator.loadEagerSingletons(InternalInjectorCreator.java:213),
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184),
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:111),
	at com.google.inject.Guice.createInjector(Guice.java:87),
	at com.google.inject.Guice.createInjector(Guice.java:78),
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:200),
	at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:155),
	at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21),
	at play.core.server.ProdServerStart$.start(ProdServerStart.scala:54),
	at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30),
	at play.core.server.ProdServerStart.main(ProdServerStart.scala),
,
4 errors,
	at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:554),
	at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:188),
	at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:111),
	at com.google.inject.Guice.createInjector(Guice.java:87),
	at com.google.inject.Guice.createInjector(Guice.java:78),
	at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:200),
	at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:155),
	at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21),
	at play.core.server.ProdServerStart$.start(ProdServerStart.scala:54),
	at play.core.server.ProdServerStart$.main(ProdServerStart.scala:30),
	at play.core.server.ProdServerStart.main(ProdServerStart.scala),

@almothafar I tested this issue with the latest release 22.03RC1 it seems to be working on my side. Would you be able to check it ?

@PierreAdam I can't confirm it right now except in my own time in my home, as I left the company that I worked for that using play.

@almothafar alright ! Well I think the problem is solved, I'm gonna do some more testing and if everything is alright on my side, I'll close the ticket !
Thank you for you answer ! Take care

@almothafar I just did some more testing. It seems fine to me. Here was my test.

Configuration file

ebean {
  servers {
    default {
      enhancement = ["models.*", "database.models.*", "test.extramodels.*"]
    }
    mysql {
      enhancement = ["mysql.models.*"]
    }
  }
}

This is my log output with Ebean traces which seems fine.

2022-03-08 11:21:59 DEBUG io.ebean.internal  BeanPersistControllers[0] BeanFinders[0] BeanPersistListeners[0] BeanQueryAdapters[0] BeanPostLoaders[0] BeanPostConstructors[0]
2022-03-08 11:21:59 TRACE io.ebean.internal  BeanDescriptor initialise test.extramodels.TestModel
2022-03-08 11:21:59 TRACE io.ebean.internal  BeanDescriptor initialise database.models.AuthorModel
2022-03-08 11:21:59 TRACE io.ebean.internal  BeanDescriptor initialise database.models.TaskModel
2022-03-08 11:21:59 TRACE io.ebean.internal  BeanDescriptor initialise models.TimeSpentModel
2022-03-08 11:22:00 DEBUG io.ebean.internal  Entities[4]

I also did some insert / select works well.
I'm closing the ticket as it seems fine for me. If you have any more trouble with it, feel free to re-open it ! :)
Best regards !