JSF EclipseLink - I can not write information to the MySQL database

0

I am using JSF in a college subject and the teacher has passed an activity. But I'm not able to write information from a form. The connection is done, I can perform up to JPQ queries 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 can not be cast to java.lang.Long Error Code: 0

I'm using the Java connector v5.1.47. When I try to use a more up-to-date connector I can not connect to the database. Even with MySQL configured not to use encryption in the root password. Because when I used it, the connection was not made because of this encryption.

Update

Here is 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's 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();
    }
}

The error occurs on the line:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("RestManagerPU");
    
asked by anonymous 09.09.2018 / 02:06

2 answers

0

I finally figured out what the problem was. 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 5.1.47 driver, it is now working.

    
14.09.2018 / 14:43
0

By logging your error it appears to be a type (type) error.

Java seems not to be able to transform a variable type BigInteger to type Long automatically. It's probably some form field, but the log does not show what it would be.

You will have to check the data you are inserting into the database and cast (cast) to the appropriate types.

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

See Table 5.1 in Java, JDBC and MySQL Types for more information on possible conversions.

    
09.09.2018 / 02:24