samedi 27 juin 2015

Hibernate SQL Grammar Exception JPA 2.1

I am having a problem when I test my application and try to insert in a table.

In more detail, I get this exception:

http://ift.tt/1CB4QF3

Im using Hibernate as persistence provider and JPA 2.1, Java EE 7, WildFly 8.2.0 and JSF 2.2.

In JBoss 7.1.1 and Java EE 6 I have the same application and works fine, but not now...

persistence.xml

    <?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://ift.tt/1cKbVbQ"
             version="2.1"
             xmlns:xsi="http://ift.tt/ra1lAU"
             xsi:schemaLocation="http://ift.tt/1cKbVbQ http://ift.tt/1kMb4sd">

    <persistence-unit name="Agenda-PU" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
        <properties>
            <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/test_app"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.username" value="root"/>
            <property name="hibernate.connection.password" value="root"/>
            <property name="hibernate.archive.autodetection" value="class"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hbm2ddl.auto" value="create"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        </properties>
    </persistence-unit>
</persistence>

Im injecting the EJB in the ManagedBean with @EJB annotation, aparently all of the code works fine...

Here's the code of the ManagedBean:

import modelo.Usuario;
import negocio.Negocio;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@RequestScoped
public class Registro {

    @EJB
    private Negocio negocio;

    private Usuario usuario;
    private String repass;

    private String cuenta;

    private boolean registroOK;

    @PostConstruct
    public void init(){
        usuario = new Usuario();
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public String getRepass() {
        return repass;
    }

    public void setRepass(String repass) {
        this.repass = repass;
    }

    public String getCuenta() {
        return cuenta;
    }

    public void setCuenta(String cuenta) {
        this.cuenta = cuenta;
    }

    public boolean isRegistroOK() {
        return registroOK;
    }

    public void setRegistroOK(boolean registroOK) {
        this.registroOK = registroOK;
    }

    public String registrarUsuario() {
        if (!usuario.getPassword().equals(repass)) {
            FacesMessage fm = new FacesMessage("Las contraseñas deben coincidir");
            FacesContext.getCurrentInstance().addMessage("registro:repass", fm);
            return null;
        }

        Negocio.Error e = negocio.registrarUsuario(usuario);

        switch (e) {
            case CUENTA_REPETIDA:
                FacesMessage fm = new FacesMessage("Existe un usuario con la misma cuenta");
                FacesContext.getCurrentInstance().addMessage("registro:user", fm);
                return null;
        }

        registroOK=true;

        return "exitoRegistro.xhtml";
    }
}

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire