1

I am working on a project using JavaFX with a PostgreSQL database and Hibernate. For some reason, I get this exception:

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
    at java.base/java.lang.reflect.Method.invoke(Method.java:577)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1081)
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
    ... 2 more
Caused by: java.lang.ClassNotFoundException: java.sql.SQLException
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 28 more

Here is my persistence.xml file:

<persistence version="2.0"
             xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <!-- Define a name used to get an entity manager. Define that you will
    complete transactions with the DB  -->
    <persistence-unit name="universalapp" transaction-type="RESOURCE_LOCAL">

        <!-- Define the object that should be persisted in the database -->
        <class>com.ta.universalapp.Venit</class>
        <properties>
            <!-- Driver for DB database -->
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <!-- URL for DB -->
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/universal_app" />
            <!-- Username -->
            <property name="javax.persistence.jdbc.user" value="postgres" />
            <!-- Password -->
            <property name="javax.persistence.jdbc.password" value="password" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
        </properties>
    </persistence-unit>
</persistence>

And this is my main function:

private static final EntityManagerFactory ENTITY_MANAGER_FACTORY = Persistence
        .createEntityManagerFactory("universalapp");

public static void main(String[] args) {
    launch();
    getIncome(9);
    getIncomes();
    changeIncome(16, "test_new_database");
    deleteIncome(27);
    ENTITY_MANAGER_FACTORY.close();
}

I don't know what I am doing wrong.

1
  • Hi, you should provide minimal reproducible example to get help quicker ;-) What I see is not complete and reproducible... Commented Aug 4, 2022 at 15:14

1 Answer 1

1

Looks like your JavaFX application runs in module mode, but you don't configure that you application needs the java.sql module. Add --add-modules java.sql to your command line flags. Also see why is java/sql module not resolved by default from an automatic module and are there other system modules which are not resolved by default

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.