Can't find a solution?

Post questions to the Ebean forum at: Ebean google group

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.

 

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.test : ebean-test-config is a test dependency

See docs / testing for setting up ebean-test-config

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.<init>(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)
	...

 

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 / tooling for more details on enhancement