我使用持久性单元和实体类从数据库,所有在一个JavaFx fxml应用程序,我成功地导入我所有的表作为实体在我的模型,问题是,我得到一个异常和错误,当我试图插入到一个实体,这里是我的整个代码
主要:
package com.example.systemzarzadzaniahurtownia;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.io.IOException;
public class Main extends Application {
private static EntityManagerFactory factory = Persistence.createEntityManagerFactory("thePersistenceUnit");
private static EntityManager em = factory.createEntityManager();
@Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Home.fxml"));
stage.setResizable(false);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
错误:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.NoClassDefFoundError: java/sql/SQLException
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.jboss.logging.Logger.doGetMessageLogger(Logger.java:2562)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2530)
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516)
at [email protected]/org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:28)
at [email protected]/org.hibernate.internal.HEMLogging.messageLogger(HEMLogging.java:24)
at [email protected]/org.hibernate.jpa.boot.internal.PersistenceXmlParser.<clinit>(PersistenceXmlParser.java:54)
at [email protected]/org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:81)
at [email protected]/org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:61)
at [email protected]/org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:50)
at [email protected]/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at [email protected]/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.example.systemzarzadzaniamagazynem/com.example.systemzarzadzaniahurtownia.Main.<clinit>(Main.java:14)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:467)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:366)
... 5 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:520)
... 25 more
Persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence 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_1_0.xsd" version="1.0">
<persistence-unit name="thePersistenceUnit" transaction-type="RESOURCE_LOCAL">
<class>Entity.Dostawcy</class>
<class>Entity.DostawyId</class>
<class>Entity.Dostawy</class>
<class>Entity.DostawyId</class>
<class>Entity.Dostawy</class>
<class>Entity.Kategorie</class>
<class>Entity.Klienci</class>
<class>Entity.Towary</class>
<class>Entity.Zamowienia</class>
<class>Entity.ZamWieniaTowaruId</class>
<class>Entity.ZamWieniaTowaru</class>
<class>Entity.DostawyId</class>
<class>Entity.Dostawy</class>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/hurtownia" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect" />
<property name="hibernate.use_sql_comments" value="true" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>
</persistence-unit>
</persistence>
我不知道错误在哪里。感谢每一个答案。
Connector
project structure
Error
2条答案
按热度按时间f1tvaqid1#
jdbc是missing,你可以安装连接器第一https://dev.mysql.com/downloads/connector/j/
goucqfw62#
检查您的
module-info.java
文件。应该有一个...还有...