I am using Hibernate and I have a problem inserting a PERSON table, the exception is sent:
Exception (org.hibernate.exception.SQLGrammarException) org.hibernate.exception.SQLGrammarException: could not extract ResultSet
and in the detail of the exception it sends me the SQL error:
ERROR: ORA-00942: table or view does not exist
I am using ORACLE for my database and I generate my POJOS with hibernate.reveng.xml
BEAN:
@ManagedBean (name = "personasBean")
@ViewScoped
public class PersonasBean {
//Informacion basica: Esta es la informacion que se va a agregar en la tabla persona
private String nombre1;
private String nombre2;
private String apellido1;
private String apellido2;
private int tipoDocumento;
private String numeroDocumento;
private Date fechaNacimiento;
private int lugarNacimiento;
private int grupoSanguineo;
private String rh;
private int sexo;
private String telefono;
private String celular;
private String direccion;
private String email;
//Campos adicionales con los que se manejan las validaciones y los mensajes
private boolean status = true;
private int codeMensaje;
private String mensaje;
private PersonasImplBO personasImplBO;
@PostConstruct
public void init()
{
setPersonasImplBO(new PersonasImplBO());
}
public void ingresarPersona()
{
try {
getPersonasImplBO().agregarPersona(this);
} catch (Exception e) {
setCodeMensaje(4);
setMensaje(e.getMessage());
}
mostrarAlerta();
}
public void actualizarPersona()
{
try {
getPersonasImplBO().actualizarPersona(this);
} catch (Exception e) {
setCodeMensaje(4);
setMensaje(e.getMessage());
}
mostrarAlerta();
}
public void eliminarPersona()
{
try {
getPersonasImplBO().eliminarPersona(this);
} catch (Exception e) {
setCodeMensaje(4);
setMensaje(e.getMessage());
}
mostrarAlerta();
}
public void mostrarAlerta() {
if (getCodeMensaje() == 1) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Información", getMensaje()));
}
if (getCodeMensaje() == 2) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Alerta", getMensaje()));
}
if (getCodeMensaje() == 3) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", getMensaje()));
}
if (getCodeMensaje() == 4) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL, "Error Fatal", getMensaje()));
}
}
DAO:
@Override
public int insert(Session session, GimPersona persona) throws Exception {
return Integer.parseInt(session.save(persona).toString());
}
/*
@Override
public GimPersona insert(Session session, GimPersona persona) throws Exception {
return (GimPersona) session.save(persona);
}
*/
@Override
public boolean update(Session session, GimPersona persona) throws Exception {
session.update(persona);
return true;
}
@Override
public List<GimPersona> getAll(Session session) throws Exception {
return session.createCriteria(GimPersona.class).list();
}
@Override
public GimPersona getPersonaByID(Session session, int id) throws Exception {
return (GimPersona) session.createCriteria(GimPersona.class)
.add(Restrictions.eq("persId", id))
.uniqueResult();
}
@Override
public GimPersona getPersonaByDoc(Session session, String doc) throws Exception {
return (GimPersona) session.createCriteria(GimPersona.class)
.add(Restrictions.eq("persNumerodocumento", doc))
.uniqueResult();
}
PERSONA.XML HIBERNATE
<hibernate-mapping>
<class name="Pojo.GimPersona" table="GIM_PERSONA" schema="ALBERTO" optimistic-lock="version">
<comment>TABLA PERSONAS DE LA BASE DE DATOS EN DONDE SE ALMACENAN TODAS LAS PERSONAS QUE SE REGISTRAN</comment>
<id name="persId" type="big_decimal">
<column name="PERS_ID" precision="22" scale="0" />
<generator class="sequence" />
</id>
<property name="persNombre1" type="string">
<column name="PERS_NOMBRE1" length="50" not-null="true">
<comment>PRIMER NOMBRE DE LA PERSONA</comment>
</column>
</property>
<property name="persNombre2" type="string">
<column name="PERS_NOMBRE2" length="50">
<comment>SEGUNDO NOMBRE DE LA PERSONA</comment>
</column>
</property>
<property name="persApellido1" type="string">
<column name="PERS_APELLIDO1" length="50" not-null="true">
<comment>PRIMER APELLIDO DE LA PERSONA</comment>
</column>
</property>
<property name="persApellido2" type="string">
<column name="PERS_APELLIDO2" length="50" not-null="true">
<comment>SEGUNDO APELLIDO DE LA PERSONA</comment>
</column>
</property>
<property name="persTipodocumento" type="big_decimal">
<column name="PERS_TIPODOCUMENTO" precision="22" scale="0" not-null="true">
<comment>TIPO DE DOCUMENTO QUE VA ENLAZADO CON LA TABLA DE PARAMETROS</comment>
</column>
</property>
<property name="persFechanacimiento" type="date">
<column name="PERS_FECHANACIMIENTO" length="7">
<comment>FECHA DE NACIMIENTO DE LA PERSONA</comment>
</column>
</property>
<property name="persLugarnacimiento" type="big_decimal">
<column name="PERS_LUGARNACIMIENTO" precision="22" scale="0">
<comment>LUGAR DE NACIMIENTO DE LA PERSONA</comment>
</column>
</property>
<property name="persGruposanguineo" type="big_decimal">
<column name="PERS_GRUPOSANGUINEO" precision="22" scale="0" not-null="true">
<comment>GRUPO SANGUINEO DE LA PERSONA</comment>
</column>
</property>
<property name="persRh" type="string">
<column name="PERS_RH" length="10" not-null="true">
<comment>RH DE LA PERSONA (POSITIVO - NEGATIVO)</comment>
</column>
</property>
<property name="persSexo" type="big_decimal">
<column name="PERS_SEXO" precision="22" scale="0" not-null="true">
<comment>SEXO DE LA PERSONA</comment>
</column>
</property>
<property name="persFechafinal" type="date">
<column name="PERS_FECHAFINAL" length="7">
<comment>FECHA EN LA QUE LA PERSONA DESAPARECE DE LA PLATAFORMA</comment>
</column>
</property>
<property name="persFechainicial" type="date">
<column name="PERS_FECHAINICIAL" length="7" not-null="true">
<comment>FECHA EN LA QUE LA PERSONA INGRESA EN LA PLATAFORMA</comment>
</column>
</property>
<property name="persEstado" type="big_decimal">
<column name="PERS_ESTADO" precision="22" scale="0" not-null="true">
<comment>ESTADO DE LA PERSONA(ACTIVO - INACTIVO)</comment>
</column>
</property>
<property name="persNumerodocumento" type="string">
<column name="PERS_NUMERODOCUMENTO" length="30" not-null="true" unique="true">
<comment>NUMERO DE DOCUMENTO DE LA PERSONA</comment>
</column>
</property>
<property name="persEmail" type="string">
<column name="PERS_EMAIL" length="60" not-null="true">
<comment>EMAIL DE LA PERSONA</comment>
</column>
</property>
<set name="gimUsuarios" table="GIM_USUARIO" inverse="true" lazy="true" fetch="select">
<key>
<column name="PERS_ID" precision="22" scale="0" not-null="true">
<comment>FORANEA DE LA PERSONA A LA CUAL PERTENECE EL USUARIO</comment>
</column>
</key>
<one-to-many class="Pojo.GimUsuario" />
</set>
<set name="gimClientes" table="GIM_CLIENTE" inverse="true" lazy="true" fetch="select">
<key>
<column name="PERS_ID" precision="22" scale="0" not-null="true">
<comment>PERSONA REGISTRADA DEL CLIENTE</comment>
</column>
</key>
<one-to-many class="Pojo.GimCliente" />
</set>
<set name="gimInstructors" table="GIM_INSTRUCTOR" inverse="true" lazy="true" fetch="select">
<key>
<column name="PERS_ID" precision="22" scale="0" not-null="true">
<comment>ID DE LA PERSONA DEL INSTRUCTOR</comment>
</column>
</key>
<one-to-many class="Pojo.GimInstructor" />
</set>
<set name="gimTelefonos" table="GIM_TELEFONO" inverse="true" lazy="true" fetch="select">
<key>
<column name="PERS_ID" precision="22" scale="0" not-null="true">
<comment>PERSONA A LA QUE PERTENECE EL TELEFONO</comment>
</column>
</key>
<one-to-many class="Pojo.GimTelefono" />
</set>
<set name="gimDireccions" table="GIM_DIRECCION" inverse="true" lazy="true" fetch="select">
<key>
<column name="PERS_ID" precision="22" scale="0" not-null="true">
<comment>ID DE LA PERSONA A LA CUAL PERTENECE LA DIRECCION</comment>
</column>
</key>
<one-to-many class="Pojo.GimDireccion" />
</set>
</class>
</hibernate-mapping
>
PERSONA.JAVA
public class GimPersona implements java.io.Serializable {
private BigDecimal persId;
private String persNombre1;
private String persNombre2;
private String persApellido1;
private String persApellido2;
private BigDecimal persTipodocumento;
private Date persFechanacimiento;
private BigDecimal persLugarnacimiento;
private BigDecimal persGruposanguineo;
private String persRh;
private BigDecimal persSexo;
private Date persFechafinal;
private Date persFechainicial;
private BigDecimal persEstado;
private String persNumerodocumento;
private String persEmail;
private Set gimUsuarios = new HashSet(0);
private Set gimClientes = new HashSet(0);
private Set gimInstructors = new HashSet(0);
private Set gimTelefonos = new HashSet(0);
private Set gimDireccions = new HashSet(0);
public GimPersona() {
}
public GimPersona(BigDecimal persId, String persNombre1, String persApellido1, String persApellido2, BigDecimal persTipodocumento, BigDecimal persGruposanguineo, String persRh, BigDecimal persSexo, Date persFechainicial, BigDecimal persEstado, String persNumerodocumento, String persEmail) {
this.persId = persId;
this.persNombre1 = persNombre1;
this.persApellido1 = persApellido1;
this.persApellido2 = persApellido2;
this.persTipodocumento = persTipodocumento;
this.persGruposanguineo = persGruposanguineo;
this.persRh = persRh;
this.persSexo = persSexo;
this.persFechainicial = persFechainicial;
this.persEstado = persEstado;
this.persNumerodocumento = persNumerodocumento;
this.persEmail = persEmail;
}
public GimPersona(BigDecimal persId, String persNombre1, String persNombre2, String persApellido1, String persApellido2, BigDecimal persTipodocumento, Date persFechanacimiento, BigDecimal persLugarnacimiento, BigDecimal persGruposanguineo, String persRh, BigDecimal persSexo, Date persFechafinal, Date persFechainicial, BigDecimal persEstado, String persNumerodocumento, String persEmail) {
this.persId = persId;
this.persNombre1 = persNombre1;
this.persNombre2 = persNombre2;
this.persApellido1 = persApellido1;
this.persApellido2 = persApellido2;
this.persTipodocumento = persTipodocumento;
this.persFechanacimiento = persFechanacimiento;
this.persLugarnacimiento = persLugarnacimiento;
this.persGruposanguineo = persGruposanguineo;
this.persRh = persRh;
this.persSexo = persSexo;
this.persFechafinal = persFechafinal;
this.persFechainicial = persFechainicial;
this.persEstado = persEstado;
this.persNumerodocumento = persNumerodocumento;
this.persEmail = persEmail;
}