Hibernate Does Not Delete

1

Good night guys ... I'm learning Hibernate and had a problem:

I was able to insert, retrieve the DB data ... I had a setback that I corrected by adding the following command line in the RUN settings:

--add-modules java.xml.bind

But at the time of deleting I had this setback!

follow my code:

package aplication;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import Dominio.Pessoa;

public class Programa {

    public static void main(String[] args) {

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("exemplo-jpa");
        EntityManager em = emf.createEntityManager();

        Pessoa p = em.find(Pessoa.class, 1);

        em.remove(p);

        System.out.println("Pronto!");
        em.close();
        emf.close();
    }

}

In BD I have the record, where Hibernate searches for ID 1 which is this record below:

  

1 - Someone's name - Someone

When you run the program it does not work and 4 warnigs appear:

  

WARNING: An illegal reflective access operation has occurred WARNING:   Illegal reflective access by javassist.util.proxy.SecurityActions   (file: / C: /ws/AulaJPA/lib/javassist-3.20.0-GA.jar) to method   java.lang.ClassLoader.defineClass (java.lang.String, byte [], int, int, java.security.ProtectionDomain)   WARNING: Please consider reporting this to the maintainers of   javassist.util.proxy.SecurityActions   WARNING: Use   --illegal-access = warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be   denied in a future release

I put the command shown in the warning in the configuration of the execution:

--illegal-access=warn

it returned only one warning:

  

WARNING: Illegal reflective access by   javassist.util.proxy.SecurityActions   (file: / C: /ws/AulaJPA/lib/javassist-3.20.0-GA.jar) to method   java.lang.ClassLoader.defineClass (java.lang.String, byte [], int, int, java.security.ProtectionDomain)

After searching better I found the same error and the resolution would be the following command:

--add-opens java.base/java.lang=ALL-UNNAMED

Beauty ... I rode, and there was no Warning, but it did not erase from my BD!

I'm using JDK 10 ...

I'm downloading the latest stable version of Hibernate that supports JDK version 8+ to see if it's not incompatible!

Would anyone know to tell me what's going on?

Thank you!

    
asked by anonymous 27.07.2018 / 03:07

1 answer

1

Try to add em.flush(); after em.remove(p); .

Regarding these warnings , they are the result of the modularization concept introduced in Java 9. Many developers who use reflection were displeased with these changes ended up causing several unexpected problems. Despite this, at least for now, you do not have to worry about these warnings .

    
27.07.2018 / 05:38