Can't find a solution?

Post questions to the Ebean forum at: Ebean google group or at: Ebean github discussions

java.lang.IllegalStateException: Bean class _ is not enhanced?

Actions

1. Check that the IDE enhancement plugin for IDEA or Eclipse is installed
2. Check that the enhancement plugin for maven or gradle is being used

See docs / getting started for more details on enhancement.

NullPointerException using Query beans

Example

new QCustomer
  .name.istartsWith("rob")  //   <-- Getting NPE here
  .findList()

Diagnosis

For Java: The query beans or the code using the query beans is not being enhanced.

For Kotlin: The query beans are not being enhanced.

Actions

1. Check the querybean-packages entry in ebean.mf

For Java: We need to enhance both the code that is using the query beans and the query beans themselves. The packages specified by querybean-packages needs to include the code that is using the query beans.

For Kotlin: For Kotlin we only need to enhance the query beans themselves (and not the calling code). For Kotlin the querybean-packages just needs to include the query beans.

Note that since 12.1.8 we no longer need ebean.mf to support query bean enhancement.

NullPointerException in EntityBeanIntercept

Example

Caused by: java.lang.NullPointerException: null
at io.ebean.bean.EntityBeanIntercept.isLoadedProperty(EntityBeanIntercept.java:509)
at io.ebean.bean.EntityBeanIntercept.preGetter(EntityBeanIntercept.java:914)
at models.Security._ebean_get_status(Security.java:6)

Diagnosis

For Java:There is probably a @OnetoMany or a @ManyToOne mapping that is faulty.

For Kotlin:There is probably a @OnetoMany or a @ManyToOne mapping that is faulty.

Actions

1. Check the mappings in the model class that is throwing the exception.
In our example above, it is the models.Security class. Comment out each mapping until the exception goes away, then you have identified the problem.

 

RuntimeException: Is class org.example.domain.Foo registered?

Diagnosis

Ebean does not think the bean in question is an entity bean, or we are explicitly registering entity beans (via ServerConfig.addClass()) and have not added the entity bean to that.

Actions

1. Check that the bean has @Entity annotation
2. Register the entity bean if necessary

If the entity beans are being explicit registered via serverConfig.addClass() then it could be that this entity bean class needs to also be included.

Typically stacktrace
Caused by: java.lang.RuntimeException: Error with association to [class org.example.domain.Contact]
 from [org.example.domain.Customer.contacts]. Is class org.example.domain.Contact registered?
 at io.ebeaninternal.server.deploy.parse.AnnotationAssocManys.readToOne(AnnotationAssocManys.java:476)
 at io.ebeaninternal.server.deploy.parse.AnnotationAssocManys.read(AnnotationAssocManys.java:73)
 at io.ebeaninternal.server.deploy.parse.AnnotationAssocManys.parse(AnnotationAssocManys.java:64)
 at io.ebeaninternal.server.deploy.parse.ReadAnnotations.readAssociations(ReadAnnotations.java:50)
 ... 37 more

 

DataSource user is null?

Actions

1. Check that there is a application-test.yml (or equivalent) to specify the datasource
2. Check that io.ebean : ebean-test is a test dependency

See docs / testing for setting up ebean-test

Typically stacktrace
ERROR io.ebean.Ebean - Error trying to create the default EbeanServer
 java.lang.RuntimeException: DataSource user is null?
 at org.avaje.datasource.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:207)
 at org.avaje.datasource.core.Factory.createPool(Factory.java:15)
 at io.ebeaninternal.server.core.DefaultContainer.getDataSourceFromConfig(DefaultContainer.java:273)
 at io.ebeaninternal.server.core.DefaultContainer.setDataSource(DefaultContainer.java:217)
 ...

Transient Initialisation

Actions

1. Explicitly add a default constructor to the entity bean that has the error. This constructor will initialise all the fields including the transient fields and ebean will use this constructor instead of adding a default constructor.
2. OR (NOT RECOMMENDED) add src/resources/ebean.mf with transient-init-error: false to turn off this error. This is not recommended but can be used to support old behavior if desired. In this case the transient fields will be left uninitialised when an instance is created by ebean.

Diagnosis

This is an error thrown by ebean-agent when it is enhancing an entity bean that does not have a default constructor and the code in the constructor contains code that initialises transient (non-persistent) fields in a way that the ebean-agent is unable to support.

If a transient field is initialised in a constructor it must use a simple <init> using a no argument default constructor of a type. Initialisation via any other means is not supported (using a method or non-default constructors are not supported).

When this limitation is hit we can opt to add a default constructor ourselves. In this way we get full control and ebean-agent does not need to add a default constructor.

Note that "Not Supported" in effect means that ebean-agent is not be able to initialise those transient fields in the default constructor that it is adding. Those fields will be uninitialised so null, 0, false etc when ebean creates the instance [using this default constructor, when we use transient-init-error: false].

Typically stacktrace
ebean-enhance> cls: test/model/BeanWithInvalidTransientInit  msg: Error during transform java.lang.RuntimeException:
  ERROR: Entity class without default constructor has unsupported initialisation of transient fields.
  Entity class: test/model/BeanWithInvalidTransientInit - Unsupported initialisation of transient fields - [invalidTransientInitWithoutDefaultConstructor, invalidTransientInitViaMethod]
  Refer: https://ebean.io/docs/trouble-shooting#transient-initialisation
java.lang.RuntimeException: ERROR: Entity class without default constructor has unsupported initialisation of transient fields. Entity class: test/model/BeanWithInvalidTransientInit - Unsupported initialisation of transient fields - [invalidTransientInitWithoutDefaultConstructor, invalidTransientInitViaMethod] Refer: https://ebean.io/docs/trouble-shooting#transient-initialisation
        at io.ebean.enhance.entity.DefaultConstructor.add(DefaultConstructor.java:26)
        at io.ebean.enhance.entity.ClassAdapterEntity.visitEnd(ClassAdapterEntity.java:214)
        at io.ebean.enhance.asm.ClassReader.accept(ClassReader.java:748)
        at io.ebean.enhance.asm.ClassReader.accept(ClassReader.java:424)
        at io.ebean.enhance.Transformer.entityEnhancement(Transformer.java:266)
        at io.ebean.enhance.Transformer.enhanceEntityAndTransactional(Transformer.java:223)
        at io.ebean.enhance.Transformer.transform(Transformer.java:178)
        at io.ebean.enhance.common.InputStreamTransform.transform(InputStreamTransform.java:53)
        at io.ebean.enhance.common.InputStreamTransform.transform(InputStreamTransform.java:41)
        at io.ebean.enhance.ant.OfflineFileTransform.transformFile(OfflineFileTransform.java:148)
        at io.ebean.enhance.ant.OfflineFileTransform.processPackage(OfflineFileTransform.java:132)
        at io.ebean.enhance.ant.OfflineFileTransform.processPackage(OfflineFileTransform.java:124)
        at io.ebean.enhance.ant.OfflineFileTransform.processPackage(OfflineFileTransform.java:124)
        at io.ebean.enhance.ant.OfflineFileTransform.process(OfflineFileTransform.java:66)
        at io.ebean.enhance.maven.AbstractEnhance.executeFor(AbstractEnhance.java:77)
        at io.ebean.enhance.maven.TestEnhanceMojo.execute(TestEnhanceMojo.java:27)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)

Note that Ebean version 13.12.0 enabled this error by default.