CINXE.COM
Trouble shooting | Ebean ORM
<!doctype html> <html lang="en"> <head> <title>Trouble shooting | Ebean ORM</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="shortcut icon" href="/images/favicon.ico"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Source+Sans+Pro|Ubuntu&display=swap"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous"> <link rel="stylesheet" href="/css/reset3.css"> <link rel="stylesheet" href="/css/site3.css"> <link rel="stylesheet" href="/css/pygments3.css"> </head> <body> <div id="main"> <div id="banner"> <header> <nav id="top"> <h1 id="breadcrumb"> <a class="nav-logo" href="/"><img src="/images/logo-200.png" height="35"></a> <a href="/docs">Documentation</a><span class="sep"> / </span><a href="/docs/intro/">Introduction</a><span class="sep"> / </span><span class="last">Trouble shooting</span> </h1> <ul> <li> <a href="https://github.com/ebean-orm/website-source/blob/master/docs/trouble-shooting.html"><i class="fab fa-github"></i> edit page</a> </li> <li><a onclick="toggleTheme();" title="switch dark light theme"><i class="fas fa-adjust"></i></a></li> </ul> </nav> </header> </div> <div class="grid grid-docs"> <aside> <nav class="side"> <ul> <li class="nav0 "> <a href="/docs/getting-started">Getting started</a> </li> <li class="nav0 active"> <a class="active" href="/docs/intro">Introduction</a> <ul> <li class="nav1 "> <a href="/docs/intro/database">Database & DB</a> </li> <li class="nav1 "> <a href="/docs/intro/configuration">Configuration</a> </li> <li class="nav1 "> <a href="/docs/intro/first-entity">First entity</a> </li> <li class="nav1 "> <a href="/docs/intro/queries">Queries</a> </li> <li class="nav1 "> <a href="/docs/intro/logging">Logging</a> </li> <li class="nav1 "> <a href="/docs/intro/db-migrations">DB Migrations</a> </li> <li class="nav1 "> <a href="/docs/intro/limitations">Limitations</a> </li> <li class="nav1 active"> <a class="active" href="/docs/trouble-shooting">Trouble shooting</a> </li> </ul> </li> <li class="nav0 "> <a href="/docs">Documentation</a> </li> <li class="nav0 "> <a href="/support">Getting help</a> </li> <li class="nav0 "> <a target="_blank" href="/apidoc/13">API Javadoc</a> </li> <li class="nav0 "> <a href="/videos">Videos</a> </li> <li class="nav0 "> <a href="/docs/upgrading">Upgrading</a> </li> <li class="nav0 "> <a href="/releases">Releases</a> </li> </ul> </nav> </aside> <article> <form action="https://www.google.com/search" method="get" class="inline-form"> <input type="hidden" name="as_sitesearch" value="ebean.io"> <div id="page-search"> <div class="input-group"> <input class="frm" name="q" id="searchinput" type="text" placeholder="Search... (press 's' to focus)" data-placeholder-focus="Search... (use '↑', '↓' and '⏎' to select results)" data-placeholder-blur="Search... (press 's' to focus)" autocomplete="off"> <div class="input-group-btn"> <button class="frm" type="submit"><i class="fas fa-search"></i></button> </div> </div> <div id="page-search-results" style="display: none;"> <ul id="search-results-container" class="search-results"><li class=" active"><a href="/docs" title="Docs"><span style="color:#777;">Docs</span> Documentation </a></li><li class=""><small style="color:#999;">And 101 more...</small></li></ul> </div> </div> </form> <h2>Can't find a solution?</h2> <p> Post questions to the Ebean forum at: <a href="https://groups.google.com/forum/#!forum/ebean">Ebean google group</a> or at: <a href="https://github.com/ebean-orm/ebean/discussions">Ebean github discussions</a> </p> <h2 id="not-enhanced">java.lang.IllegalStateException: Bean class _ is not enhanced?</h2> <h4>Actions</h4> <h5>1. Check that the IDE enhancement plugin for <a href="/docs/getting-started/intellij-idea">IDEA</a> or <a href="/docs/getting-started/eclipse-ide">Eclipse</a> is installed</h5> <h5>2. Check that the enhancement plugin for <a href="/docs/getting-started/maven">maven</a> or <a href="/docs/getting-started/gradle">gradle</a> is being used</h5> <p> See <a href="/docs/getting-started">docs / getting started</a> for more details on enhancement. </p> <h2 id="npe-querybeans">NullPointerException using Query beans</h2> <h4>Example</h4> <div class="syntax java"><div class="highlight"><pre><span></span><span class="k">new</span> <span class="n">QCustomer</span> <span class="o">.</span><span class="na field">name</span><span class="o">.</span><span class="na">istartsWith</span><span class="o">(</span><span class="s">"rob"</span><span class="o">)</span> <span class="c1">// <-- Getting NPE here</span> <span class="o">.</span><span class="na">findList</span><span class="o">()</span> </pre></div> </div> <h4>Diagnosis</h4> <p> <b>For Java:</b> The query beans or the code using the query beans is not being enhanced. </p> <p> <b>For Kotlin:</b> The query beans are not being enhanced. </p> <h4>Actions</h4> <h5>1. Check the <code>querybean-packages</code> entry in ebean.mf</h5> <p> <b>For Java:</b> We need to enhance both the code that is using the query beans and the query beans themselves. The packages specified by <code>querybean-packages</code> needs to include the code that is using the query beans. </p> <p> <b>For Kotlin:</b> For Kotlin we only need to enhance the query beans themselves (and not the calling code). For Kotlin the <code>querybean-packages</code> just needs to include the query beans. </p> <p> Note that since 12.1.8 we no longer need ebean.mf to support query bean enhancement. </p> <h2 id="npe-bean">NullPointerException in EntityBeanIntercept</h2> <h4>Example</h4> <pre>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) </pre> <h4>Diagnosis</h4> <p> <b>For Java:</b>There is probably a <code>@OnetoMany</code> or a <code>@ManyToOne</code> mapping that is faulty. </p> <p> <b>For Kotlin:</b>There is probably a <code>@OnetoMany</code> or a <code>@ManyToOne</code> mapping that is faulty. </p> <h4>Actions</h4> <h5>1. Check the mappings in the model class that is throwing the exception.</h5>In our example above, it is the <code>models.Security</code> class. Comment out each mapping until the exception goes away, then you have identified the problem. <p> </p> <h2 id="registered">RuntimeException: Is class org.example.domain.Foo registered?</h2> <h4>Diagnosis</h4> <p> 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. </p> <h4>Actions</h4> <h5>1. Check that the bean has <code>@Entity</code> annotation</h5> <h5>2. Register the entity bean if necessary</h5> <p> If the entity beans are being explicit registered via <code>serverConfig.addClass()</code> then it could be that this entity bean class needs to also be included. </p> <h5>Typically stacktrace</h5> <div class="syntax text"><div class="highlight"><pre><span></span>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 </pre></div> </div> <p> </p> <h2 id="datasource">DataSource user is null?</h2> <h4>Actions</h4> <h5>1. Check that there is a application-test.yml (or equivalent) to specify the datasource</h5> <h5>2. Check that <code>io.ebean : ebean-test</code> is a test dependency </h5> <p> See <a href="/docs/testing">docs / testing</a> for setting up <code>ebean-test</code> </p> <h5>Typically stacktrace</h5> <div class="syntax text"><div class="highlight"><pre><span></span>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) ... </pre></div> </div> <h2 id="transient-initialisation">Transient Initialisation</h2> <h4>Actions</h4> <h5>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. </h5> <h5>2. OR (NOT RECOMMENDED) add <code>src/resources/ebean.mf</code> with <code>transient-init-error: false</code> 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. </h5> <h4>Diagnosis</h4> <p> This is an error thrown by <em>ebean-agent</em> 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. </p> <p> 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). </p> <p> 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. </p> <p> 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 <code>transient-init-error: false</code>]. </p> <h5>Typically stacktrace</h5> <div class="syntax text"><div class="highlight"><pre><span></span>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) </pre></div> </div> <p> Note that Ebean version <code>13.12.0</code> enabled this error by default. </p> <nav class="next"> <p class="edit-page"> <a href="https://github.com/ebean-orm/website-source/blob/master/docs/trouble-shooting.html"><i class="fab fa-github"></i> Edit Page</a> </p> </nav> </article> </div> </div> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="/js/site3.js"></script> <script src="/js/search3.js"></script> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-75181644-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-75181644-1'); </script> </body> </html>