SQLGrammarException:ORA-00904(“无效标识符") [英] SQLGrammarException: ORA-00904 ("invalid identifier")

查看:341
本文介绍了SQLGrammarException:ORA-00904(“无效标识符")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对使用JPA和Spring的Java类运行JUnit测试时,出现Oracle错误/org.hibernate.exception.SQLGrammarException:

I'm getting an Oracle error / org.hibernate.exception.SQLGrammarException when I run a JUnit test against a Java class which uses JPA and Spring:

ORA-00904: "ALIAS"."COLUMN_NAME": invalid identifier

奇怪的是,当针对开发数据库运行JUnit测试时,它运行正常,但是当针对我用于持续集成构建的数据库(它们都是Oracle数据库)运行时,JUnit测试失败.

The odd thing is that the JUnit test works when run against a development database but fails when run against a database which I use for Continuous Integration builds (they are both Oracle databases).

因此,这表明后者的d/b中缺少某些内容或出现了问题.但是,我已经两次(和三次)检查所引用的表在两个数据库中是否相同,并且包含错​​误所引用的COLUMN_NAME列.

Therefore, this would suggest that there's something missing or awry in the latter d/b. However, I have double- (and triple-)checked that the table referred to is identical in both databases and contains the column COLUMN_NAME that the error is referring to.

更多信息-在JUnit测试中调用的DAO Java类使用javax.persistence.EntityManager:

Further information - the DAO Java class invoked in the JUnit test uses a javax.persistence.EntityManager:

MyClass myObject = entityManager.find(MyClass.class, idNumber);

MyClass JPA实体类映射到Oracle表:

The MyClass JPA entity class maps onto the Oracle table:

@Configurable
@Entity
@Table(name = "MyTable", schema = "MySchema")
public class MyClass implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MY_SEQ")
    @SequenceGenerator(name = "MY_SEQ", sequenceName = "MY_SEQ", allocationSize = 1)
    @Column(name = "ID")
    protected BigDecimal id;

    @Column(name = "COLUMN_NAME")
    private String columnName;
    ...
}

两个数据库的数据库表中的COLUMN_NAME列均为VARCHAR2(50),并且可以为空.

The column COLUMN_NAME in the database table in both databases is VARCHAR2(50) and nullable.

版本:

Java-1.6

春季-3.1.1

Oracle-11.2.0.3.0

Oracle - 11.2.0.3.0

在此先感谢您的帮助.

推荐答案

发现了问题.我发现了Hibernate正在创建的查询(通过添加

Found the problem. I found the query that Hibernate was creating (by adding

<property name="hibernate.show_sql" value="true" />

到我的data-persistence.xml文件),并尝试在测试失败的数据库中运行它.它表明,在实体Java类中,关联的数据库表是这样定义的:

to my data-persistence.xml file) and tried to run it in the database where the test was failing. It transpires that in the entity Java class, the associated database table is defined like this:

@Table(name = "MyTable", schema = "MySchema")

...对开发d/b来说效果很好.但是,持续集成数据库具有在称为其他"的架构中创建的所有表,因此会出现错误.

... which works fine against the development d/b. However, the continuous integration database has all the tables created in a schema called something else, hence the error.

感谢大家的帮助.

这篇关于SQLGrammarException:ORA-00904(“无效标识符")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆