How to resolve ERROR: HHH000346: Error During Managed flush [org.hibernate.Exception.Sqlgrammarexception: could not execute statement]

Asked

Viewed 1,359 times

0

When I try to run my test class I get this error below. I don’t know what else to do, when I comment on the attribute FOLDERAUTOUPDATE class ApplicationItv the insertion in the bank works, but I need it.

Can someone help me?

INFO: HHH000400: Using dialect: org.hibernate.dialect.OracleDialect
dez 10, 2018 8:35:00 AM org.hibernate.dialect.Oracle9Dialect <init>
WARN: HHH000063: The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
dez 10, 2018 8:35:00 AM org.hibernate.dialect.OracleDialect <init>
WARN: HHH000064: The OracleDialect dialect has been deprecated; use Oracle8iDialect instead
Hibernate: 
    select
        SEQ_APPLICATION_ITV.nextval 
    from
        dual
Hibernate: 
    insert 
    into
        APPLICATION_ITV
        (bandWidth, folderAutoUpdate, name, who, id) 
    values
        (?, ?, ?, ?, ?)
dez 10, 2018 8:35:01 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 904, SQLState: 42000
dez 10, 2018 8:35:01 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ORA-00904: "FOLDERAUTOUPDATE": identificador inválido

dez 10, 2018 8:35:01 AM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]
Falha no banco de dados: 
ORA-00904: "FOLDERAUTOUPDATE": identificador inválido

The database for this table:

CRIAÇÃO DO BANCO DE DADOS

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

The XML of persistence:

<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="bancoItv">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>br.com.sky.iTvMC.modelo.ApplicationItv</class> 
    <class>br.com.sky.iTvMC.modelo.AppointmentCategory</class> 
    <class>br.com.sky.iTvMC.modelo.Bit</class> 
    <class>br.com.sky.iTvMC.modelo.Channel</class> 
    <class>br.com.sky.iTvMC.modelo.ChannelCategory</class>
    <class>br.com.sky.iTvMC.modelo.City</class> 
    <class>br.com.sky.iTvMC.modelo.ClientChannel</class> 
    <class>br.com.sky.iTvMC.modelo.ClientChannelAppointment</class> 
    <class>br.com.sky.iTvMC.modelo.Image</class> 
    <class>br.com.sky.iTvMC.modelo.ImageCategory</class>
    <class>br.com.sky.iTvMC.modelo.Segmentation</class> 
    <class>br.com.sky.iTvMC.modelo.SegmentationRules</class> 
    <class>br.com.sky.iTvMC.modelo.Video</class> 
    <class>br.com.sky.iTvMC.modelo.VideoArtist</class> 
    <class>br.com.sky.iTvMC.modelo.VideoCategory</class> 

    <properties>
        <!-- Propriedades JDBC -->
        <property name="javax.persistence.jdbc.driver" 
value="oracle.jdbc.OracleDriver" />
        <property name="javax.persistence.jdbc.url" 
value="jdbc:oracle:thin:@10.16.2.30:1521:apps" />
        <property name="javax.persistence.jdbc.user" value="itv" />
        <property name="javax.persistence.jdbc.password" value="itvsky2015" 
/>
        <!-- Configuracoes especificas do Hibernate -->
        <property name="hibernate.dialect" 
 value="org.hibernate.dialect.OracleDialect" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <!-- poderia ser: update, create, create-drop, none -->
        <property name="hibernate.hbm2ddl.auto" value="none" />
    </properties>
</persistence-unit>
</persistence>

My DAO :

package br.com.sky.iTvMC.dao;

import java.util.List;
import javax.persistence.EntityManager;
import br.com.sky.iTvMC.modelo.ApplicationItv;

public class ApplicationItvDao {

private EntityManager manager;

public ApplicationItvDao(EntityManager manager) {
    this.manager = manager;
}

public void add(ApplicationItv applicationItv) {
    this.manager.persist(applicationItv);
}

public void remove(ApplicationItv applicationItv) {
    this.manager.remove(applicationItv);
}

public void update(ApplicationItv applicationItv) {
    this.manager.merge(applicationItv);
}

public ApplicationItv find(Integer id) {
    return this.manager.find(ApplicationItv.class, id);
}

public List<ApplicationItv> list() {
    return this.manager.createQuery("SELECT * FROM APPLICATION_ITV",     
    ApplicationItv.class).getResultList();
}
}

My Test Class:

package br.com.sky.iTvMC.teste;
import javax.persistence.EntityManager;
import br.com.sky.iTvMC.dao.ApplicationItvDao;
import br.com.sky.iTvMC.modelo.ApplicationItv;
import br.com.sky.iTvMC.util.*;

public class testandoApplicationItv {

public static void main(String[] args) {
    try {
        EntityManager manager = new JPAUtil().getEntityManager();

        ApplicationItvDao dao = new ApplicationItvDao(manager);
        ApplicationItv applicationItv = new ApplicationItv();

        applicationItv.setName("Canal do cliente HD");          
        applicationItv.setBandWidth(230);
        applicationItv.setFolderAutoUpdate("pasta/teste");
        applicationItv.setWho("funcionaroio");          



        manager.getTransaction().begin();
        dao.add(applicationItv);
        manager.getTransaction().commit();
        manager.close();
        System.out.println(applicationItv);
    } catch (Exception e) {
        BDUtil bdUtil = new BDUtil();
        bdUtil.trataSQLException(e);
    }

}

}

My Model Class:

package br.com.sky.iTvMC.modelo;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Table(name = "APPLICATION_ITV")
@Entity
public class ApplicationItv {
@SequenceGenerator(name = "seqAppItv", sequenceName = "SEQ_APPLICATION_ITV", 
allocationSize = 1)
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqAppItv")
private Integer id;
private String name;
private Integer bandWidth;
private String folderAutoUpdate;
private String who;

public String getWho() {
    return who;
}

public void setWho(String who) {
    this.who = who;
}

public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Integer getBandWidth() {
    return bandWidth;
}

public void setBandWidth(Integer bandWidth) {
    this.bandWidth = bandWidth;
}

public String getFolderAutoUpdate() {
    return folderAutoUpdate;
}

public void setFolderAutoUpdate(String folderAutoUpdate) {
    this.folderAutoUpdate = folderAutoUpdate;
}
}

3 answers

0

This error usually happens with Hibernate/JPA when we map our entities and the database already exists, and the framework is not responsible for generating the database scripts.

So in the case as already exists the table APPLICATION_ITV your entity must have the correct mapping to the table, so you must use the annotation attributes @Column.

 @Column(name="NAME")
 private String name;

 @Column(name="BANDWIDTH")
 private Integer bandWidth;

 @Column(name="AUTO_UPDATE_FOLDER")
 private String folderAutoUpdate;

 @Column(name="WHO")
 private String who;

0


You have not noted your columns correctly when you do not use Annotation @Column(name="MINHACOLUNA") by default Hibernate will consider the name of the class property.

I noticed the column in the case is called AUTO_UPDATE_FOLDER, so note your attribute with @Column(name="AUTO_UPDATE_FOLDER"), do this for other simple, unmapped properties that cause error.

0

The mistake you’re making is this:

ORA-00904: "FOLDERAUTOUPDATE": invalid identifier

Looking at your code, the problem is that you did not create a column with this name in the database. You created a column with the name AUTO_UPDATE_FOLDER and not FOLDERAUTOUPDATE.

To solve, you can match the column name in the database creation to FOLDERAUTOUPDATE or map the correct column name in the entity with:

@Column(name = "AUTO_UPDATE_FOLDER")
private String folderAutoUpdate;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.