0
I am using JSF in a college subject and the teacher has passed an activity. But I am not able to record information from a form. The connection is made, I can even perform JPQL queries straight from Netbeans, but when I try to save 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 the Java connector v5.1.47. When I try to use a more up-to-date connector I cannot connect to the database. Even with Mysql configured not to use root password encryption. Because when I used, the connection wasn’t made because of this encryption.
Updating
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 is 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");
But the Usuarios object has all String attributes, I created them by backup engineering by Netbeans itself. So the attribute types match the database columns.
– Leandro Souza
I looked here at the debugging and the error does not occur when writing the data to the database, occurs when trying to create the connection
– Leandro Souza
Yes, he says he couldn’t connect WHY he couldn’t cast the variable. " Connection could not be allocated because: java.lang.Classcastexception: java.math.Biginteger cannot be cast to java.lang.Long". I would need to see how you process the form data and try to insert it into the BD. That’s where the problem should be.
– Gus Neves