简体   繁体   English

从Spring Boot查询Oracle数据库时表名称无效

[英]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: 我正在尝试从Spring Boot查阅oracle表,但我没有成功,我遇到的问题是:

"2018-04-10 12:32:10.623 ERROR 22668 --- [ restartedMain] ohengine.jdbc.spi.SqlExceptionHelper : ORA-00903: nombre de tabla no v├ílido" “ 2018-04-10 12:32:10.623错误22668 --- [restartedMain] ohengine.jdbc.spi.SqlExceptionHelper:ORA-00903:密码没有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: 这是我的OracloDBConfig类:

@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: 这是我在控制台输出上的“ Caused by”错误:

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. 在Oracle端上验证您的许可。

    2.1 Execute the select statement in SQL developer using the same credentials. 2.1使用相同的凭据在SQL Developer中执行select语句。 Verify no errors. 验证没有错误。 If errors then see next step. 如果有错误,请参阅下一步。

    2.2 Execute the following in SQL Developer. 2.2在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. 2.3验证表名称BUG和架构XXXXXXX。 Then use that schema in you select statement. 然后在选择语句中使用该架构。

    SELECT * FROM your_schema.bug;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从数据库中检索一个值并将其设置为 Spring boot 中的 @Table Name 值 - Retrieve a value from Database and set it as @Table Name value in Spring boot 制作Spring Boot应用程序以从现有的oracle数据库加载数据吗? - Making a spring boot app to load data from an existing oracle database? Spring引导服务从oracle数据库返回大数据集 - Spring boot service to return large datasets from oracle database 使用 Spring 引导从 Oracle 数据库获取实体不起作用 - Use Spring Boot get entity from Oracle DataBase not work 从Spring Boot调用Oracle PL / SQL函数时出错 - Error while calling an Oracle PL/SQL function from Spring Boot Spring Boot 无法从 Oracle 数据库中获取正确的数据 - Spring Boot not fetching correct data from Oracle database 从spring boot应用程序连接到oracle数据库时如何解决“驱动程序不支持获取/设置连接网络超时”的问题? - How to fix "Driver does not support get/set network timeout for connections" while connecting to oracle database from spring boot app? Spring Boot + AWS Linux + Oracle 数据库 - Spring boot + AWS Linux + Oracle database 如何使用spring boot连接oracle数据库 - How to connect to oracle database using spring boot 防止@Entity 重新创建数据库表 - Spring 引导 - Prevent @Entity from re creating a database table - Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM