0
votes

I have already execute the below query in order to create the table ACCOUNT in my Oracle DB:

CREATE TABLE ACCOUNT

( TESTACC   VARCHAR2(13 BYTE)             NOT NULL,
  TEST        VARCHAR2(3 BYTE)           DEFAULT 'TEST',

   CONSTRAINT TEST_PK
   PRIMARY KEY
   (TESTACC)

  )

Then I create a GRAILS domain

class Account {

String testAcc
String test

static constraints = {  
    testAcc     nullable: false 
 }

static mapping = {
    table "ACCOUNT"
    id                      name: "testAcc"
    testAcc                 column: "ID"
    test                    column: "TEST"

}

Now, I am trying to execute the query below in GRAILS console :

Account.executeQuery("select u.test from Account u")

But I facing this issue :

org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: ORA-00904: "ACCOUNT"."TEST": invalid identifier
1
yes it is a typo, it is updated now - SK7
Are you connected to the same user as you have created table with? - atokpas
yes, the same user - SK7
The table already contains data, so I wonder if some constraints are missing especially when we talk about nullable - SK7

1 Answers

0
votes

The domain entity Account is poorly defined.

Try this:

class Account {

    String testacc
    String test

    static constraints = {  
        testacc     maxSize:13
        test        nullable: true, blank: true, maxSize:3 
    }

    static mapping = {
        id generator: 'assigned', name: "testacc", type: 'string'
    }
}

In your code table "ACCOUNT" and test column: "TEST" are redundant.

Also keep in mind that when you define String testAcc GORM will try to find (or create) TEST_ACC column.