How to resolve ERROR: HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]

0

When I try to run my test class, I get this error below. I do not know what to do anymore, when I comment on the FOLDERAUTOUPDATE attribute of the class ApplicationItv the insertion works in the bank, however I need it.

Can anyone 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:

ThepersistenceXML:

<persistenceversion="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 Class Model:

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;
}
}
    
asked by anonymous 10.12.2018 / 11:39

3 answers

0

You did not annotate your columns correctly, when you do not use @Column(name="MINHACOLUNA") annotation by default Hibernate will consider the class property name.

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

    
17.12.2018 / 16:01
0

The error you are having 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 have created a column named AUTO_UPDATE_FOLDER and not FOLDERAUTOUPDATE .

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

@Column(name = "AUTO_UPDATE_FOLDER")
private String folderAutoUpdate;
    
17.12.2018 / 16:03
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 case the APPLICATION_ITV table already exists, your entity must have the correct mapping for the table, so you should use the @Column p>

 @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;
    
04.01.2019 / 20:31