Schema Primary Key not Inline Throws Runtime Exception in EJB3 Entity Generation
Description
Environment
org.springframework:spring-orm:6.2.1
org.hibernate.orm:hibernate-core:6.6.4.Final
org.hibernate.orm:hibernate-community-dialects -> 6.6.4.Final
org.xerial:sqlite-jdbc -> 3.47.1.0
JDK: corretto-21.0.5
OS: Linux Mint 22 Cinnamon 6.2.9
Database: SQLite
Attachments
1
- 23 Dec 2024, 12:35 AM
Activity
Show:
WiseNat December 23, 2024 at 12:35 AM
Above is a record-less example of the DB to support issue replication.
Details
Details
Assignee
Unassigned
UnassignedReporter
WiseNat
WiseNatBug Testcase Reminder (view)
Bug reports should generally be accompanied by a test case!
Bug Testcase Reminder (edit)
Bug reports should generally be accompanied by a test case!
Participants
WiseNat
Affects versions
Priority
Created December 23, 2024 at 12:34 AM
Updated February 10, 2025 at 2:18 PM
When I try to run the following Hibernate Tools Ant task through Gradle (apologies, I couldn’t get your Gradle version working) I get an Exception.
tasks.register("hibernatetool") { description = "Generates JPA Entities" group = JavaBasePlugin.DOCUMENTATION_GROUP doLast { ant.withGroovyBuilder { "path"( "id" to "ejb3toolslib" ) { // "path"("refid" to "jpatoolslib") "path"("location" to "lib/hibernate-annotations.jar") // "path"("location" to "lib/ejb3-persistence.jar") "path"("location" to "lib/hibernate-entitymanager.jar") // "path"("location" to "lib/jboss-archive-browsing.jar") // "path"("location" to "lib/javaassist.jar") } "taskdef"( "name" to "hibernatetool", "classname" to "org.hibernate.tool.ant.HibernateToolTask", "classpath" to configurations.getByName("hibernateTools").asPath, ) "hibernatetool"( "destdir" to "src/main/java/", // TODO: Investigate this ) { "classpath" { configurations.getByName("hibernateTools").files.forEach { file -> "pathelement"("location" to file.absolutePath) } configurations.getByName("runtimeClasspath").files.forEach { file -> "pathelement"("location" to file.absolutePath) } } "jdbcconfiguration"( "packagename" to "tech.nathanwise.ares.newentity", "revengfile" to "hibernate.reveng.xml", "propertyfile" to "hibernate.properties" ) // "hbmtemplate" { // "property"("key" to "ejb3", "value" to "true") // } // "hbm2java"( "ejb3" to "true" ) } } } }
2024-12-23T00:27:52.866+0000 [ERROR] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:hibernatetool] An exception occurred while running exporter #2:hbm2java (Generates a set of .java files) 2024-12-23T00:27:52.866+0000 [ERROR] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:hibernatetool] To get the full stack trace run ant with -verbose 2024-12-23T00:27:52.866+0000 [ERROR] [org.gradle.api.internal.project.ant.AntLoggingAdapter] [ant:hibernatetool] java.lang.RuntimeException: sqltype is null for Table: BATTLES column: `"id" AUTOINCREMENT` 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':ares-entities:hibernatetool'. 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > java.lang.RuntimeException: sqltype is null for Table: BATTLES column: `"id" AUTOINCREMENT` 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try: 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Run with --stacktrace option to get the stack trace. 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Run with --scan to get full insights. 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Get more help at https://help.gradle.org. 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] 2024-12-23T00:27:52.873+0000 [ERROR] [org.gradle.internal.buildevents.BuildResultLogger] BUILD FAILED in 1s
Through Table create generation with https://sqlitebrowser.org/ the Autoincrement Primary Key is defined on a separate line, such as id in this BATTLES table:
CREATE TABLE "BATTLES" ( "id" INTEGER, "user_one_id" INTEGER NOT NULL UNIQUE, "user_two_id" INTEGER NOT NULL UNIQUE, PRIMARY KEY("id" AUTOINCREMENT), FOREIGN KEY("user_one_id") REFERENCES "USERS"("id"), FOREIGN KEY("user_two_id") REFERENCES "USERS"("id") )
This can be resolved user-side by simply changing the schema to the following:
CREATE TABLE "BATTLES" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT , "user_one_id" INTEGER NOT NULL UNIQUE, "user_two_id" INTEGER NOT NULL UNIQUE, FOREIGN KEY("user_one_id") REFERENCES "USERS"("id"), FOREIGN KEY("user_two_id") REFERENCES "USERS"("id") )
However, this means that all Tables created through DB Browser for SQLite require schema modification after creation to get JPA Entity generation working through Hibernate Tools.
I appreciate this is most likely a minor incompatibility issue but I thought I’d raise it nonetheless.