JSF EclipseLink-I can't write information to MySQL database

I am using JSF in a faculty subject and the professor passed an activity. But I am not being able to record information from a form. The connection is made, I can even perform queries in JPQL direct from Netbeans, but when I try to write information entered by a form the following error appears:

Javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services-2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long Error Code: 0

I am using Java connector V5.1.47. When I try to use a more updated connector I can not perform the connection to the database. Even with MySQL configured not to use encryption on root password. Because when I used it, the connection was not carried out because of this encryption.

Update

Here's my persistence.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" 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_1.xsd">
  <persistence-unit name="RestManagerPU" transaction-type="JTA">
    <jta-data-source>java:app/RestManager</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.schema-generation.database.action" value="create"/>
    </properties>
  </persistence-unit>
</persistence>

And here is the DAOHelper, where the error occurs:

*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

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

/**
 *
 * @author leand
 */
public class DAOHelper {
    public EntityManager getEM(){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("RestManagerPU");
        return emf.createEntityManager();
    }
}

Error occurs on line:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("RestManagerPU");
Author: Leandro Souza, 2018-09-09

2 answers

From the log of your error appears to be a type error.

Java doesn't seem to be able to turn a variable type BigInteger to type Long automatically. It's probably some form field, but the log doesn't show what it would be.

You will have to check the data you are entering in the database and cast it to the appropriate types.

If you are using MySQL, you should probably use java.math.BigDecimal to transform BigInteger in Long.

See table 5.1 in Java, JDBC and MySQL Types for more information on possible conversions.
insert the description of the image here

 0
Author: Gus Neves, 2018-09-09 00:24:53

I finally managed to figure out what the problem is. For some reason the JDBC driver does not work with MySQL 8, even the 8.0.12 driver. I installed MySQL 5.7 and for the connection I used the driver 5.1.47, now it is working.

 0
Author: Leandro Souza, 2018-09-14 12:43:51