38

I see an error while executing hibernate sql query.

java.sql.SQLException: ORA-00904: "table_name"."column_name": invalid identifier

When I open up the table in sqldeveloper, the column is present.

The error is only happening in PROD, not in DEV.

What should I check?

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Victor
  • 16,609
  • 71
  • 229
  • 409

14 Answers14

37

ORA-00904-invalid identifier errors are frequently caused by case-sensitivity issues. Normally, Oracle tables and columns are not case sensitive and cannot contain punctuation marks and spaces. But if you use double quotes to create a quoted identifier, that identifier must always be referenced with double quotes and with the correct case. For example:

create table bad_design("goodLuckSelectingThisColumn  " number);
Jon Heller
  • 34,999
  • 6
  • 74
  • 132
  • in my case, it was because of case-sensitivity; so I renamed my column in oracle from column_name to COLUMN_NAME and the problem get solved – hakima maarouf Aug 09 '22 at 14:26
10

Oracle will throw ORA-00904 if executing user does not have proper permissions on objects involved in the query.

vls
  • 2,304
  • 15
  • 20
8

This happened to me when I accidentally defined two entities with the same persistent database table. In one of the tables the column in question did exist, in the other not. When attempting to persist an object (of the type referring to the wrong underlying database table), this error occurred.

johanwannheden
  • 852
  • 8
  • 8
5

Write the column name in between DOUBLE quote as in "columnName".

If the error message shows a different character case than what you wrote, it is very likely that your sql client performed an automatic case conversion for you. Use double quote to bypass that. (This works on Squirrell Client 3.0).

Arc
  • 167
  • 1
  • 4
4

It is because one of the DBs the column was created with " which makes its name case-sensitive.

Oracle Table Column Name : GoodRec Hive cannot recognize case sensitivity : ERROR thrown was - Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "GOODREC": invalid identifier

Solution : Rename Oracle column name to all caps.

Piyush Ugale
  • 101
  • 1
  • 4
3

check the position of Column annotation in java class for the field For Example,consider one table with name STUDENT with 3 column(Name,Roll_No,Marks).

Then make sure you have added below annotation of column before Getter Method instead of Setter method. It will solve ur problem @Column(name = "Name", length = 100)

**@Column(name = "NAME", length = 100)
public String getName() {**
    return name;
}

    public void setName(String name) {
    this.name= name;
}
yogi
  • 31
  • 1
2

Have you compared the table definitions in Prod and Dev?

And when you are running it in SQL Developer, are you running the query in Prod (same database as the application) and with the same user?

If there are some additional columns that you are adding (using an alter command) and these changes are not yet promoted to prod, this issue is possible.

Can you post the definition of the table and your actual Query?

Rajesh Chamarthi
  • 18,568
  • 4
  • 40
  • 67
1

Seems like Oracle is throwing this error in many cases.

For me it was thrown, because I tried to qualify a column that was used in using clause in the join part. None of there two will work:

select table1.x -- doesn't work
from table1
join table2 using (x);

select t1.x -- doesn't work
from table1 t1
join table2 t2 using(x);

It's because we can qualify the column from using clause with neither table name nor alias. The correct way would be:

select x
from table1
join table2 using (x);

select x
from table1 t1
join table2 t2 using(x);
Andronicus
  • 25,419
  • 17
  • 47
  • 88
1

I was seeing this error for a slightly different reason to those given above:

I'd used a liquibase script to modify my already-existing (Oracle) table. Everything looked fine but the inserts in my code were failing. Only when I saw that I was being offered enclosing quotes by SQL Developer's auto-completion did I see that a space had been appended to the column name at creation.

The offending liquibase changeSet line looked like this (single space before the 'MY_FIELD' closing quote):

<addColumn tableName="MY_TABLE">
    <column name="MY_FIELD " type="tinyint" defaultValueNumeric="3">
        <constraints nullable="false"/>
    </column>
</addColumn>
H.C.
  • 11
  • 1
  • Correct me if I am wrong. Are you referring to https://stackoverflow.com/questions/6027961/ora-00904-invalid-identifier – Nadeem Taj Aug 19 '21 at 17:41
  • 1
    Hi Nadeem - no, I was referring to the ORA-00904 error I was getting when the column I was trying to insert to (plus an invisible space) was present, this post. Although maybe the other post raises a similar issue, I didn't go through it in any detail. Edit: having said that, it's the same error message (although I got it in a different language), but I wasn't knowingly referring to the other post ;) – H.C. Aug 20 '21 at 13:15
0

I use Toad for Oracle and if the table is owned by another username than the one you logged in as and you have access to read the table, you still may need to add the original table owner to the table name.

For example, lets say the table owner's name is 'OWNER1' and you are logged in as 'USER1'. This query may give you a ORA-00904 error:

select * from table_name where x='test';

Prefixing the table_name with the table owner eliminated the error and gives results:

select * from 
gnat
  • 6,213
  • 108
  • 53
  • 73
0

Its due to mismatch between column name defined in entity and the column name of table (in SQL db )

java.sql.SQLException: ORA-00904: "table_name"."column_name": invalid identifier e.g.java.sql.SQLException: ORA-00904: "STUDENT"."NAME": invalid identifier

issue can be like in Student.java(entity file) 
You have mentioned column name as "NAME" only.
But in STUDENT table ,column name is lets say "NMAE"

Vivek Singh
  • 959
  • 7
  • 10
0

Check for synonym declaration in Oracle. I was calling an PL/SQL function as below and it was giving java.sql.SQLSyntaxErrorException: ORA-00904: invalid identifier

select oracle_my_pkg.notify_list_function from dual

after declaring a public synonym for oracle_my_pkg the error message was gone

akarahman
  • 235
  • 2
  • 15
0

create a new table. but don't give the values in "(double quotes) that's look like only solution

create table bad_design(goodLuckSelectingThisColumn  number);

insted of

create table bad_design("goodLuckSelectingThisColumn  " number);
Krunal Akbari
  • 316
  • 1
  • 17
  • 2
    Welcome to StackOverflow. Your answer does not provide any additional information than the accepted answer. Please extend it with valuable insight or delete your post. – Peter Csala Sep 28 '21 at 10:11
-1

Check the username credential used to login to the database. (persistence.xml ??). The problem mostly is, the username\password used to login to the database, does not have visiblity to the object (table_name in this case). ( try logging in to sql developer, using the same username\password available in your data source)

uncaught_exceptions
  • 21,712
  • 4
  • 41
  • 48
  • 1
    Won't that give a table not found instead? SQL> select colA from invalid_table_name; select colA from invalid_table_name * ERROR at line 1: ORA-00942: table or view does not exist – Rajesh Chamarthi Apr 19 '11 at 21:25
  • There is no persistence.xml. Hibernate is using the datasource defined on the websphere – Victor Apr 19 '11 at 21:29
  • I am not saying that the table object does not exists. I am saying that there is a visibility problem. Did he not say that he logged in to sqldeveloper and found everything to be alright... The only thing, I could think of is,there is a difference in username. (schema) – uncaught_exceptions Apr 19 '11 at 21:31
  • Then check your datasource configuration. It should have connection string and username\password credentials right... (in jboss its oracle-ds.xml.. I do not know abt Websphere. – uncaught_exceptions Apr 19 '11 at 21:32
  • I was trying to say that if there was a visibility problem (grants), then the error would be "Table does not exist" instead. The error that the OP posted indicates that he has access to the table, but the column name is missing or he is using an alias to the column name incorrectly. – Rajesh Chamarthi Apr 20 '11 at 02:19