简体   繁体   中英

invalid table name while consulting a oracle database from spring boot

I'm trying to consult an oracle table from spring boot but i have not success, the problem i have is:

"2018-04-10 12:32:10.623 ERROR 22668 --- [ restartedMain] ohengine.jdbc.spi.SqlExceptionHelper : ORA-00903: nombre de tabla no válido"

this are my application properties:

spring.profiles.active=dev
spring.session.store-type=jdbc
spring.jpa.hibernate.ddl-auto=none

spring.datasource.url=jdbc:oracle:thin:@notmyserver:1521:lnkqhp 
spring.datasource.username=notmyuser
spring.datasource.password=notmypass
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

spring2.datasource.driver-class-name=org.h2.Driver
spring2.datasource.url=jdbc:h2:file:~/test;MODE=MYSQL;DB_CLOSE_DELAY=-1...
spring2.datasource.username=sa
spring2.datasource.password=

spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

spring.h2.console.enabled=true

spring.jpa.database=default

spring.thymeleaf.mode=LEGACYHTML5

This is my OracloDBConfig class:

@Configuration
@Profile("prod")
public class OracleDbConfig {

@Autowired
private ApplicationContext appContext;

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory2() {
    System.out.println(" ########### ENTRANDO A entityManagerFactory ####################");
    HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setDatabase(Database.ORACLE);
    LocalContainerEntityManagerFactoryBean emfb = new LocalContainerEntityManagerFactoryBean();
    System.out.println("****** Datasource: "+appContext.getBean(DataSource.class));
    emfb.setDataSource(appContext.getBean(DataSource.class));
    emfb.setPersistenceUnitName("entityManagerFactory2");
    emfb.setPackagesToScan("com.reportes.domain");
    emfb.setJpaVendorAdapter(adapter);
    return emfb;
}

@Bean
public DataSource db2Datasource() {
    DriverManagerDataSource dataSource
            = new DriverManagerDataSource();
    dataSource.setDriverClassName(
            appContext.getEnvironment().getProperty("jdbc.driver-class-name"));
    dataSource.setUrl(appContext.getEnvironment().getProperty("spring.datasource.url"));
    dataSource.setUsername(appContext.getEnvironment().getProperty("spring.datasource.username"));
    dataSource.setPassword(appContext.getEnvironment().getProperty("spring.datasource.password"));

    return dataSource;
}

@Bean
public PlatformTransactionManager transactionManager2(EntityManagerFactory emf) {
    System.out.println(" ########### ENTRANDO A transactionManager ,. ####################");
    return new JpaTransactionManager(emf);
}

}

this is my entity:

@Entity(name = "BUG")
@Table(name = "BUG", schema = "LINK_REDMOB_MOBILE_DB")
public class Bug implements Serializable{

@Id
@Column(name = "BG_BUG_ID")
private int BG_BUG_ID;
@Column(name = "BG_STATUS")
private  String BG_STATUS;
@Column(name = "BG_DETECTION_DATE")
private  String  BG_DETECTION_DATE;
@Column(name = "BG_DETECTED_BY")
private  String BG_DETECTED_BY;
@Column(name = "BG_RESPONSIBLE")
private  String BG_RESPONSIBLE;
@Column(name = "BG_SEVERITY")
private  String BG_SEVERITY;
@Column(name = "BG_SUMMARY")
private  String BG_SUMMARY;
@Column(name = "BG_DESCRIPTION")
private  String BG_DESCRIPTION;
@Column(name = "BG_DEV_COMMENTS")
private  String BG_DEV_COMMENTS;



public Bug() {
}

public Bug(
        int BG_BUG_ID,
        String BG_STATUS,
        String BG_DETECTION_DATE,
        String BG_DETECTED_BY,
        String BG_RESPONSIBLE,
        String BG_SEVERITY,
        String BG_SUMMARY,
        String BG_DESCRIPTION,
        String BG_DEV_COMMENTS

) {
    this.BG_BUG_ID = BG_BUG_ID;
    this.BG_STATUS = BG_STATUS;
    this.BG_DETECTION_DATE = BG_DETECTION_DATE;
    this.BG_DETECTED_BY = BG_DETECTED_BY;
    this.BG_RESPONSIBLE = BG_RESPONSIBLE;
    this.BG_SEVERITY = BG_SEVERITY;
    this.BG_SUMMARY = BG_SUMMARY;
    this.BG_DESCRIPTION = BG_DESCRIPTION;
    this.BG_DEV_COMMENTS = BG_DEV_COMMENTS;
}



public int getBG_BUG_ID() {
    return BG_BUG_ID;
}

public String getBG_STATUS() {
    return BG_STATUS;
}

public String getBG_DETECTION_DATE() {
    return BG_DETECTION_DATE;
}

public String getBG_DETECTED_BY() {
    return BG_DETECTED_BY;
}

public String getBG_RESPONSIBLE() {
    return BG_RESPONSIBLE;
}

public String getBG_SEVERITY() {
    return BG_SEVERITY;
}

public String getBG_SUMMARY() {
    return BG_SUMMARY;
}

public String getBG_DESCRIPTION() {
    return BG_DESCRIPTION;
}

public String getBG_DEV_COMMENTS() {
    return BG_DEV_COMMENTS;
}
}

This is my repository

@Repository
public interface ReportRepository extends JpaRepository<Bug, Long> {

    @Query("SELECT BG_BUG_ID, BG_STATUS, BG_DETECTION_DATE, BG_DETECTED_BY, 
BG_RESPONSIBLE, BG_SEVERITY, BG_SUMMARY, BG_DESCRIPTION, BG_DEV_COMMENTS 
FROM LINK_REDMOB_MOBILE_DB.BUG WHERE BG_STATUS IN('Abierto','Reabierto') AND 
BG_USER_05='Diferido' 
ORDER BY BG_BUG_ID")

    List<Bug> findByDefectosDiferidos();
}

This are my "Caused by" errors on the console output:

java.lang.IllegalStateException: Failed to execute CommandLineRunner

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: 
could not extract ResultSet; SQL [n/a]; nested exception is 
org.hibernate.exception.SQLGrammarException: could not extract ResultSet

Caused by: org.hibernate.exception.SQLGrammarException: could not extract 
ResultSet

Caused by: java.sql.SQLSyntaxErrorException: ORA-00903: nombre de tabla no 
válido

What i'm doing wrong??

WHERE IS THE PROBLEM? The problem is on the configuration of the datasources in spring.

  1. Try specifying your schema like so :

    select * from your_schema.your_table;

  2. Verify your permission on the Oracle end.

    2.1 Execute the select statement in SQL developer using the same credentials. Verify no errors. If errors then see next step.

    2.2 Execute the following in SQL Developer. You should see your table and schema. If you don't see your table then there is an issue with your grant or synonyms as pointed out in the comments.

    SELECT * FROM all_tables WHERE REGEXP_LIKE(table_name, 'BUG', 'i');

    2.3 Verify the table name of BUG and schema of XXXXXXX. Then use that schema in you select statement.

    SELECT * FROM your_schema.bug;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM