Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After packaging Javalin + Ebean into a JAR file, it cannot run:jakarta.persistence.PersistenceException: hxy.dragon.model.Customer is NOT an Entity Bean registered with this server #3371

Open
aohanhongzhi opened this issue Mar 25, 2024 · 2 comments

Comments

@aohanhongzhi
Copy link

Expected behavior

Expecting it to run normally after being packaged into a JAR file.

Actual behavior

In fact, after packaging, the following error is reported when running.

Steps to reproduce

package hxy.dragon.model

import io.ebean.Model
import io.ebean.annotation.Length
import jakarta.persistence.Entity
import jakarta.persistence.Id

typealias  CustomerId = Long // 类型别名提高代码的可读性与可维护性

/**
 *  最好设置一个DAO层,用封装 ebean,否则项目大了不好调试
 */
@Entity
class Customer : Model() {

    @Id
    var id: CustomerId = 0 //默认值为 0

    var name: String? = null // 默认值为null

    @Length(100)
    var email: String? = null
}
  

console log

14:28:39.919 kotlin [JettyServerThreadPool-Virtual-9] ERROR at io.github.oshai.kotlinlogging.KLogger$DefaultImpls.error (KLogger.kt:810) - /customer/list发生异常 jakarta.persistence.PersistenceException: hxy.dragon.model.Customer is NOT an Entity Bean registered with this server?
jakarta.persistence.PersistenceException: hxy.dragon.model.Customer is NOT an Entity Bean registered with this server?
	at io.ebeaninternal.server.core.DefaultServer.desc(DefaultServer.java:1866)
	at io.ebeaninternal.server.core.DefaultServer.createQuery(DefaultServer.java:801)
	at io.ebeaninternal.server.core.DefaultServer.find(DefaultServer.java:789)
	at io.ebean.DB.find(DB.java:774)
	at hxy.dragon.service.CustomerService.list(CustomerService.kt:26)
	at hxy.dragon.controller.CustomerController.listCustomer(CustomerController.kt:27)
	at io.javalin.router.Endpoint.handle(Endpoint.kt:52)
	at io.javalin.router.ParsedEndpoint.handle(ParsedEndpoint.kt:15)
	at io.javalin.http.servlet.DefaultTasks.HTTP$lambda$9$lambda$7$lambda$6(DefaultTasks.kt:52)
	at io.javalin.http.servlet.JavalinServlet.handleTask(JavalinServlet.kt:99)
	at io.javalin.http.servlet.JavalinServlet.handleSync(JavalinServlet.kt:64)
	at io.javalin.http.servlet.JavalinServlet.handle(JavalinServlet.kt:50)
	at io.javalin.http.servlet.JavalinServlet.service(JavalinServlet.kt:30)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
	at io.javalin.jetty.JavalinJettyServlet.service(JavalinJettyServlet.kt:52)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:587)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:764)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:529)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1580)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:221)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1381)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:176)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:484)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1553)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:174)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1303)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:129)
	at org.eclipse.jetty.server.handler.StatisticsHandler.handle(StatisticsHandler.java:173)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:122)
	at org.eclipse.jetty.server.Server.handle(Server.java:563)
	at org.eclipse.jetty.server.HttpChannel$RequestDispatchable.dispatch(HttpChannel.java:1598)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:753)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:501)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:287)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:314)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:100)
	at org.eclipse.jetty.io.SelectableChannelEndPoint$1.run(SelectableChannelEndPoint.java:53)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
	at java.base/java.lang.VirtualThread.run(VirtualThread.java:311)
@rbygrave
Copy link
Member

So if the application is using the querybean-generator then that generates code so that there is no class path scanning for entity beans at startup time. If the app does not use the querybean-generator then it probably is class path scanning to find the entity beans at startup time.

The suggestion here is that querybean-generator is not being used and that the class path scanning is not working when the app is packaged up into the Jar.

The question then becomes, how is the app packaged up into a Jar? Is it using the maven shade plugin or something like that? Exactly how is it being packaged up?

@aohanhongzhi
Copy link
Author

@rbygrave thanks for you replay.
below is my project which is a gradle one.

https://github.com/aohanhongzhi/JavalinDemo-Kotlin

I package it by gradle task

// 打包
tasks.jar.configure {
    duplicatesStrategy = DuplicatesStrategy.INCLUDE
    manifest.attributes["Main-Class"] = mainKotlinClass
    from(configurations.runtimeClasspath.get().filter {
        // 只打包ebean-platform-mysql,除了这个,其他的不打包,免得SPI注入的文件给覆盖了。io.ebean.config.dbplatform.DatabasePlatformProvider
        it.name.endsWith("jar") && (it.name.contains("ebean-platform-mysql") || !it.name.contains("ebean-platform"))
    }.map { zipTree(it) })
}

so how should I solve it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants