0

this is my pom.xml file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>OBARS_V_2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>OBARS</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.9.2</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>21-ea+17</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>21-ea+17</version>
        </dependency>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>24.0.1</version>
            <scope>compile</scope>
        </dependency>

        <!-- ucanaccess dependencies -->
        <dependency>
            <groupId>net.ucanaccess</groupId>
            <artifactId>ucanaccess</artifactId>
            <version>5.0.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/ucanaccess-5.0.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>com.healthmarketscience.jackcess</groupId>
            <artifactId>jackcess</artifactId>
            <version>4.0.5</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/jackcess-3.0.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.7.1</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/lib/hsqldb-2.5.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>

        <!--     hibernate     -->
        <!-- https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-core -->
        <dependency>
            <groupId>org.hibernate.orm</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>6.2.5.Final</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>central</id>
            <name>Maven Central Repository</name>
            <url>https://repo.maven.apache.org/maven2</url>
        </repository>
    </repositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>18</source>
                    <target>18</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running with: mvn clean javafx:run -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>com.example.obars_v_2/OBARS</mainClass>
                            <launcher>app</launcher>
                            <jlinkZipName>app</jlinkZipName>
                            <jlinkImageName>app</jlinkImageName>
                            <noManPages>true</noManPages>
                            <stripDebug>true</stripDebug>
                            <noHeaderFiles>true</noHeaderFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

this is the location of my .jar files "src\main\resources\lib" enter image description here

and this is the location of my persistence.xml file "src\main\resources\META-INF\persistence.xml"

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd"
             version="2.2">
    <persistence-unit name="Patient_PU" transaction-type="RESOURCE_LOCAL">
        <properties>
            <!-- Specify the provider -->
            <property name="javax.persistence.provider" value="org.hibernate.jpa.HibernatePersistenceProvider"/>

            <!-- Configure the database connection -->
            <property name="javax.persistence.jdbc.driver" value="net.ucanaccess.jdbc.UcanaccessDriver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:ucanaccess://D:/BIS/Java/Projects/OBARS_V_2/src/main/resources/db/OBARS_.accdb"/>

            <!-- Hibernate specific properties -->
            <property name="hibernate.dialect" value="net.ucanaccess.hibernate.dialect.UcanaccessDialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>

            <!-- Entity manager factory configuration -->
            <property name="javax.persistence.schema-generation.database.action" value="none"/>
        </properties>
    </persistence-unit>
</persistence>

I use MVC architecture

package utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import java.sql.SQLException;
import java.util.List;

public abstract class GenericRepository<T> {
    private final Class<T> entityClass;
    protected EntityManager entityManager;

    public GenericRepository(Class<T> entityClass, EntityManager entityManager) {
        this.entityClass = entityClass;
        this.entityManager = entityManager;
    }

    protected T findById(Long id) throws SQLException {
        return entityManager.find(entityClass, id);
    }

    protected List<T> findAll() throws SQLException {
        CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
        CriteriaQuery<T> query = criteriaBuilder.createQuery(entityClass);
        Root<T> root = query.from(entityClass);
        query.select(root);
        return entityManager.createQuery(query).getResultList();
    }

    protected void save(T entity) throws SQLException {
        EntityTransaction transaction = entityManager.getTransaction();
        transaction.begin();
        entityManager.persist(entity);
        transaction.commit();
    }

    protected void update(T entity) throws SQLException {
        EntityTransaction transaction = entityManager.getTransaction();
        transaction.begin();
        entityManager.merge(entity);
        transaction.commit();
    }

    protected void delete(T entity) throws SQLException {
        EntityTransaction transaction = entityManager.getTransaction();
        transaction.begin();
        entityManager.remove(entity);
        transaction.commit();
    }
}

PatientDAL class

package dataAccess;

import models.Patient;
import utils.GenericRepository;

import javax.persistence.EntityManager;
import java.sql.SQLException;
import java.util.List;

public class PatientDAL extends GenericRepository<Patient> {
    public PatientDAL(EntityManager entityManager, Patient patient) throws SQLException {
        super(Patient.class, entityManager);
    }

    public void createPatient(Patient patient) throws SQLException {
        save(patient);
    }

    public Patient getPatient(long patientID) throws SQLException {
        return findById(patientID);
    }

    public List<Patient> getAlPatients() throws SQLException {
        return findAll();
    }

    public void updatePatient(Patient patient) throws SQLException {
        update(patient);
    }

    public void deletePatient(Patient patient) throws SQLException {
        delete(patient);
    }
}

PatientBLL class

package businessLogic;

import ExceptionHandlers.BusinessException;
import dataAccess.PatientDAL;
import models.Patient;
import views.Admin;
import views.Profile;

import org.jetbrains.annotations.NotNull;

import javafx.stage.Stage;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.sql.SQLException;
import java.util.List;
import java.util.regex.Pattern;

public class PatientBLL {
    private final EntityManagerFactory entityManagerFactory;
    private final EntityManager entityManager;
    private final PatientDAL patientDAL;
    private Patient patient;

    {
        try {
            // Create the EntityManagerFactory
            entityManagerFactory = Persistence.createEntityManagerFactory("Patient_PU");
            // Create the EntityManager
            entityManager = entityManagerFactory.createEntityManager();

            patientDAL = new PatientDAL(entityManager, patient);
        } catch (SQLException e) {
            e.printStackTrace();
            System.out.println("\n\n");
            throw new RuntimeException(e);
        }
    }

    // Login Constructor
    public PatientBLL(Stage loginStage, String userID, String pass) {
        loginWithUserIDAndPass(loginStage, userID, pass);
    }

    // Sign Up Constructor
    public PatientBLL(Stage signUpStage, String name, String phone, String email, String city, String address, String gender, String age, String userID, String createdPass, String confirmPass) {
        signUpWithPatientData(signUpStage, name, phone, email, city, address, gender, age, userID, createdPass, confirmPass);
    }

    /*
     *  Validate Login Form
     */
    private void loginWithUserIDAndPass(Stage loginStage, @org.jetbrains.annotations.NotNull String userID, String pass) {

        // Check if the userID & pass fields are Empty
        if (userID.isEmpty() || pass.isEmpty()) {
            System.out.println("Please, Enter Your ID And Password." + "Missing Information!");
            return;
        }

        // Check if the patient credentials are valid
        try {
            patient = this.getPatientById(Integer.parseInt(userID));
        } catch (BusinessException | NumberFormatException ex) {
            System.out.println("Wrong UserID Or Password");
            return;
        }
        if (patient == null || !patient.getPassword().equals(pass)) {
            System.out.println("Wrong UserID Or Password");
            return;
        }

        // Check if the user is an Admin or a Patient
        if (patient.getPatientId() == 1212 && patient.getPassword().equals(pass)) {
            loginStage.hide();
            new Admin();
        } else {
            loginStage.hide();
            new Profile(patient);
        }

        // then close the connection
        try {
            this.closeConnection();
        } catch (BusinessException e) {
            System.out.println("Failed to close the connection: " +  e.getMessage());
        }
    }

    /*
     *  Validate Sign Up Form
     */
    private void signUpWithPatientData(Stage signUpStage, @NotNull String name, String phone, String email, String city, String address, String gender, String age, String userID, String createPass, String confirmPass) {

        // Check if any of the input fields are Empty
        if (name.isEmpty() || phone.isEmpty() || email.isEmpty() || city.isEmpty() || address.isEmpty() || age.isEmpty() || userID.isEmpty() || createPass.isEmpty() || confirmPass.isEmpty()) {
            System.out.println("Please fill them all");
            return;
        }

        // Check if the Name is Valid
        if (!Pattern.matches("^[a-zA-Z]+(\\s[a-zA-Z]+){0,5}$", name)) {
            System.out.println("Please Enter A Valid Name");
            return;
        }

        // Check if the Phone is Valid
        if (!Pattern.matches("^[0-9]+$", phone)) {
            System.out.println("Please Enter A Valid Phone Number");
            return;
        }

        // Check if the Email is Valid
        if (!Pattern.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$", email)) {
            System.out.println("Please Enter A Valid Email");
            return;
        }

        // Check if the Age is Valid
        try {
            if (Integer.parseInt(age) <= 0 || Integer.parseInt(age) >= 110) {
                System.out.println("Please Enter A Valid Age");
                return;
            }
        } catch (NumberFormatException ex) {
            System.out.println("Please Enter A Valid Age");
            return;
        }

        // Check if the user is already Exist
        try {
            if (this.getPatientById(Integer.parseInt(userID)) != null) {
                System.out.println("This UserID IS Already Exist");
                return;
            }
        } catch (BusinessException | NumberFormatException ex) {
            System.out.println("Please Enter A Valid UserID");
            return;
        }

        // Check if the Password is Valid
        if (!Pattern.matches("^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d).{8,}$", createPass)) {
            System.out.println("Please Enter A Valid Password");
            return;
        }

        // Check if the two passwords are matched
        if (!createPass.equals(confirmPass)) {
            System.out.println("Passwords Doesn't Match");
            return;
        }

        // If everything is good so far create the Patient & go to the Profile page
        patient = new Patient(Integer.parseInt(userID), name, city, address, phone, email, Integer.parseInt(age), createPass, gender);
        try {
            this.createPatient(patient);
            this.closeConnection();
            System.out.println("Registration successful.");

            signUpStage.hide();
            new Profile(patient);
        }
        catch (BusinessException e) {
            System.out.println("Registration Failed! " + e.getMessage());
        }
    }

    /*
     *  CRUD Operations
     */
    private Patient getPatientById(long patientId) throws BusinessException {
        try {
            return patientDAL.getPatient(patientId);
        } catch (SQLException e) {
            throw new BusinessException("Failed to get patient ID. " + e.getMessage(), e);
        }
    }

    public void createPatient(Patient patient) throws BusinessException {
        try {
            patientDAL.createPatient(patient);
        } catch (SQLException e) {
            throw new BusinessException("Failed to create patient: " + e.getMessage(), e);
        }
    }

    public void closeConnection() throws BusinessException {
        // Close the EntityManager and EntityManagerFactory
        entityManager.close();
        entityManagerFactory.close();
    }
}

Patient model

package models;
import javax.persistence.*;

@Entity
public class Patient {
    // Attributes
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int patientId;
    @Column(name = "P_Full_Name", nullable = false)
    private String fullName;
    @Column(name = "P_City", nullable = false)
    private String city;
    @Column(name = "P_Address", nullable = false)
    private String address;
    @Column(name = "P_Phone", nullable = false)
    private String phone;
    @Column(name = "P_Email", nullable = false)
    private String email;
    @Column(name = "P_Gender", nullable = false)
    private String gender;
    @Column(name = "P_Age", nullable = false)
    private int age;
    @Column(name = "P_Password", nullable = false)
    private String password;
}

I use IntelliJ IDE enter image description here

I tried a lot of solutions but nothing worked I still get this error when I'm trying to log in inside the java app

javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver log
WARNING: javax.persistence.spi::No valid providers found.
Exception in thread "JavaFX Application Thread" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Patient_PU
    at java.persistence@2.2/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:85)
    at java.persistence@2.2/javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at OBARS@1.0-SNAPSHOT/businessLogic.PatientBLL.<init>(PatientBLL.java:29)
    at OBARS@1.0-SNAPSHOT/views.Login.lambda$initialize$0(Login.java:47)
    at javafx.base@21-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base@21-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
    at javafx.base@21-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
    at javafx.base@21-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@21-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@21-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@21-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@21-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@21-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@21-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@21-ea/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@21-ea/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.base@21-ea/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@21-ea/javafx.scene.Node.fireEvent(Node.java:8925)
    at javafx.controls@21-ea/javafx.scene.control.Button.fire(Button.java:203)
    at javafx.controls@21-ea/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:207)
    at javafx.controls@21-ea/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at javafx.base@21-ea/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
    at javafx.base@21-ea/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at javafx.base@21-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
    at javafx.base@21-ea/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
    at javafx.base@21-ea/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base@21-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base@21-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@21-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@21-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@21-ea/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base@21-ea/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base@21-ea/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base@21-ea/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base@21-ea/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics@21-ea/javafx.scene.Scene$MouseHandler.process(Scene.java:3984)
    at javafx.graphics@21-ea/javafx.scene.Scene.processMouseEvent(Scene.java:1890)
    at javafx.graphics@21-ea/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2708)
    at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
    at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
    at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:424)
    at javafx.graphics@21-ea/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
    at javafx.graphics@21-ea/com.sun.glass.ui.View.handleMouseEvent(View.java:551)
    at javafx.graphics@21-ea/com.sun.glass.ui.View.notifyMouse(View.java:937)
    at javafx.graphics@21-ea/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics@21-ea/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:185)
    at java.base/java.lang.Thread.run(Thread.java:1623)

0 Answers0