Como resolver este erro doido é este?

5 respostas
Jefries

Galera, o que significa este erro e como resolve-lo???

WARNING: SQL Error: -1, SQLState: 42Y07
19/07/2010 21:46:16 org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: O esquema ‘TESTE’ não existe
org.hibernate.exception.SQLGrammarException: could not get or update next value… - esta é um parte… dai tem a outra…

Caused by: java.sql.SQLSyntaxErrorException: O esquema TESTE não existe

at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)

at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)

at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source)

at org.hibernate.id.TableGenerator.doWorkInCurrentTransaction(TableGenerator.java:132)

at org.hibernate.engine.TransactionHelper$1Work.doWork(TransactionHelper.java:38)

 16 more

Se alguém puder me ajudar valeu!!!

5 Respostas

R

posta ai tua configuração de banco.

F

Ao que parece, ele esta acusando que no seu banco de dados não existe o “TESTE”. Verifique a sql que vc esta passando, se ela consulta alguma tabela ou algo assim que vc definiu com esse nome. É um palpite, nunca usei hibernete, sou child ainda nesses assuntos.

Hebert_Coelho

Cara, o problema é o Schema. Provavelmente o programa deve estar apontando para um Schema e no Banco foi criado com outro nome.

Existem bancos também que são CASE SENSITIVE. Toma cuidado com isso também.

Fernando_Generoso_da

Dá uma olhada no teu arquivo de configuração do hibernate e vê se tem alguma propriedade parecida com isso:

hibernate.default_schema

Aí deve estar o problema…

M

Boa tarde Galera,

Estou com o mesmo problema, estou utilizando o banco de dados Derby (em memória), e ao que me parece o hibernate não está conseguindo gerar a minha estrutura de banco de dados, que é composta por (schema.tabela), sendo que possuo diversos Schemas em todo o Banco de dados. No Sistema Utilizamos o Postgresql, porém estamos adotando a técnica do TDD (Test Driven Development), e para agilizar este processo optamos por utilizar um banco em memória (HSQLDB ou DERBY). Porém não estamos conseguindo da continuidade, devido a esse problema, vou postar o código de mapeamento da classe, o persistence.xml e a excessão gerada.
Se alguém souber ou puder ajudar, agradeço. :D

Mapeamento da Classe:
package br.fpf.laboratorio.entitybean;

// Generated 25/02/2008 16:05:28 by Hibernate Tools 3.2.0.b10

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

import br.fpf.saude.core.constants.IntegerConstant;

/**
 * TipoAmostra generated by hbm2java.
 */

@SuppressWarnings( "serial" )
@Entity
@Table( name = "tipo_amostra", schema = "laboratorio" )
@SequenceGenerator( name = "idTipoAmostraSequence", sequenceName = "laboratorio.tipo_amostra_id_tipo_amostra_seq" )
public class TipoAmostra implements java.io.Serializable {

    /**
	 * 
	 */
    private Integer idTipoAmostra;

    /**
	 * 
	 */
    private String txTipoAmostra;

    /**
	 * 
	 */
    private Boolean csColetaLocal;

    /**
	 * 
	 */
    private Boolean csAtivo;

    /**
	 * 
	 */
    private String txObservacao;
    
    /**
     * 
     */
    private Short nbSequencia;

    /**
	 * 
	 */
    public TipoAmostra() {
    }

    /***
	 * 
	 */
    private Set<TipoExameRecomendacao> tipoExameRecomendacaos = new HashSet<TipoExameRecomendacao>( 0 );

    /**
     * @param idTipoAmostra
     * @param txTipoAmostra
     * @param csColetaLocal
     * @param csAtivo
     */
    public TipoAmostra( int idTipoAmostra, String txTipoAmostra, Boolean csColetaLocal, Boolean csAtivo ) {
        this.idTipoAmostra = idTipoAmostra;
        this.txTipoAmostra = txTipoAmostra;
        this.csColetaLocal = csColetaLocal;
        this.csAtivo = csAtivo;
    }

    /**
     * @param idTipoAmostra
     * @param txTipoAmostra
     * @param csColetaLocal
     * @param csAtivo
     * @param txObservacao
     */
    public TipoAmostra( int idTipoAmostra, String txTipoAmostra, Boolean csColetaLocal, Boolean csAtivo,
                        String txObservacao ) {
        this.idTipoAmostra = idTipoAmostra;
        this.txTipoAmostra = txTipoAmostra;
        this.csColetaLocal = csColetaLocal;
        this.csAtivo = csAtivo;
        this.txObservacao = txObservacao;
    }

    @Id
    @Column( name = "id_tipo_amostra", unique = true )
    @GeneratedValue( strategy = GenerationType.IDENTITY, generator = "idTipoAmostraSequence" )
//    @NotNull
    public Integer getIdTipoAmostra() {
        return this.idTipoAmostra;
    }

    public void setIdTipoAmostra( Integer idTipoAmostra ) {
        this.idTipoAmostra = idTipoAmostra;
    }

    @Column( name = "tx_tipo_amostra", nullable = false, length = IntegerConstant.CINQUENTA )
//    @NotNull
//    @Length( max = IntegerConstant.CINQUENTA )
    public String getTxTipoAmostra() {
        return this.txTipoAmostra;
    }

    public void setTxTipoAmostra( String txTipoAmostra ) {
        this.txTipoAmostra = txTipoAmostra;
    }

    public void setCsColetaLocal( Boolean csColetaLocal ) {
        this.csColetaLocal = csColetaLocal;
    }

    public void setCsAtivo( Boolean csAtivo ) {
        this.csAtivo = csAtivo;
    }

    @Column( name = "tx_observacao" )
    public String getTxObservacao() {
        return this.txObservacao;
    }

    public void setTxObservacao( String txObservacao ) {
        this.txObservacao = txObservacao;
    }

    @Column( name = "cs_ativo" )
    public Boolean getCsAtivo() {
        return this.csAtivo;
    }

    @Column( name = "cs_coleta_local" )
    public Boolean getCsColetaLocal() {
        return this.csColetaLocal;
    }

    @Cascade( { org.hibernate.annotations.CascadeType.DELETE_ORPHAN, org.hibernate.annotations.CascadeType.SAVE_UPDATE,
            org.hibernate.annotations.CascadeType.MERGE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
    @OneToMany( cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }, 
            fetch = FetchType.LAZY, mappedBy = "tipoExame" )
    public Set<TipoExameRecomendacao> getTipoExameRecomendacaos() {
        return this.tipoExameRecomendacaos;
    }

    public void setTipoExameRecomendacaos( Set<TipoExameRecomendacao> tipoExameRecomendacaos ) {
        this.tipoExameRecomendacaos = tipoExameRecomendacaos;
    }
    
    /**
     * Hash para TipoExameAmostraId .
     * 
     * @return inteiro.
     */
    @Override
    public int hashCode() {
        int result = IntegerConstant.DEZESSETE;

        result = IntegerConstant.TRINTA_SETE * result;
        if ( this.getIdTipoAmostra() != null ) {
        	result += this.getIdTipoAmostra(); 
        }
     
        
        return result;
    }

    /**
     * Método verificador de equivalência.
     * 
     * @return booleano.
     */
    @Override
    public boolean equals( Object obj ) {
        if ( this == obj ) {
            return true;
        }
        if ( obj == null ) {
            return false;
        }
        final TipoAmostra other = (TipoAmostra) obj;

        if ( ( this.idTipoAmostra == null ) && ( other.getIdTipoAmostra() != null ) ) {
            return false;
        }

        if ( ( this.idTipoAmostra != null ) && ( other.getIdTipoAmostra() == null ) ) {
            return false;
        }
        
        if ( this.idTipoAmostra == null && other.getIdTipoAmostra() == null && ( 
                this != other ) ) {
            return false;
        }

        if ( this.idTipoAmostra.intValue() != other.getIdTipoAmostra().intValue() ) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.txTipoAmostra;
    }

    @Transient
    public Short getNbSequencia() {
        return nbSequencia;
    }

    
    public void setNbSequencia( Short nbSequencia ) {
        this.nbSequencia = nbSequencia;
    }
    
}
Persistence.xml :
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence" 
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" 
             version="1.0">
             
   <persistence-unit name="iDoctorTest_PU" transaction-type="RESOURCE_LOCAL">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
     
      <!-- POSTGRES
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.cache.use_query_cache" value="false"/>
         <property name="hibernate.cache.use_second_level_cache" value="false"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/iDoctorTestEntityManagerFactory" />
         <property name="hibernate.connection.password" value="senha"/>
		 <property name="hibernate.connection.username" value="root"/>
		 <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
		 <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/iDoctor"/>
		 <property name="hibernate.connection.provider_class" value="org.hibernate.connection.DriverManagerConnectionProvider"/>
		 <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
      </properties>
     -->
         
             <!-- DERBY DB -->        
         <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
       <property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/> 
       <property name="hibernate.connection.url" value="jdbc:derby:memory:iDoctor;create=true"/>  
       <property name="hibernate.connection.username" value=""/>
       <property name="hibernate.connection.password" value=""/>
       <!-- Enable Hibernate's automatic session context management -->
       <property name="current_session_context_class" value="thread"/>
       <!-- JDBC connection pool (use the built-in) -->
       <property name="connection.pool_size" value="5"/>
       <!-- Drop and re-create the database schema on startup -->
       <property name="hbm2ddl.auto" value="create-drop"/>

       <!-- helper debug settings -->
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.format_sql" value="true"/>
       
       <property name="hibernate.cache.use_query_cache" value="false"/>
         <property name="hibernate.cache.use_second_level_cache" value="false"/>
        </properties>
         
      </persistence-unit>
    
</persistence>

Excessão Gerada :

Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [br.fpf.laboratorio.entitybean.TipoAmostra] at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:40) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2163) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2643) at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:51) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298) at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181) at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107) at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49) at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87) at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38) at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592) at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596) at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213) ... 30 more Caused by: java.sql.SQLSyntaxErrorException: O esquema 'LABORATORIO' não existe at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source) at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source) at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source) at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source) at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source) at org.apache.derby.impl.jdbc.EmbedPreparedStatement.(Unknown Source) at org.apache.derby.impl.jdbc.EmbedPreparedStatement20.(Unknown Source) at org.apache.derby.impl.jdbc.EmbedPreparedStatement30.(Unknown Source) at org.apache.derby.impl.jdbc.EmbedPreparedStatement40.(Unknown Source) at org.apache.derby.jdbc.Driver40.newEmbedPreparedStatement(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source) at org.apache.derby.impl.jdbc.EmbedConnection.prepareStatement(Unknown Source) at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505) at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94) at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:30)

Muito Obrigado.

Criado 19 de julho de 2010
Ultima resposta 26 de jan. de 2011
Respostas 5
Participantes 6