Scaffolding an Oracle table without an ID column in Grails

212 Views Asked by At

I'm creating a Grails 3 app with some tables from my Oracle 12c database scaffolded and while so far everything went fast, I came across one problematic table which doesn't have an ID column. It's just four VARCHAR2's. Also, in the Constraints tab of the Oracle SQL Developer, I don't see any of them defined as the Primary Key. How should one progress in such a scenario to successfully create a CRUD for this class?

I've tried telling Grails to use the row id as an ID but this only results in a "getLong not implemented for class oracle.jdbc.driver.T4CRowidAccessor" error when I try accessing the (to-be) scaffolded page. My code looks like this:

class AliasFrequencyDict {
    String frequency
    String unit
    String description
    String lang

    static constraints = {
        frequency maxSize: 10, sqlType: 'VARCHAR2'
        unit maxSize: 1, sqlType: 'VARCHAR2'
        description maxSize: 30, sqlType: 'VARCHAR2'
        lang maxSize: 2, sqlType: 'VARCHAR2'
    }

    static mapping = {
        sort 'frequency'
        version false
        id column: 'ROWID'
    }
}

How should I solve this if I don't have an explicit ID column and I am not allowed to create one?

EDIT: So the only way I was able to progress so far was to use a composite key consisting of all the columns and then manually change the index view so that instead of this:

<f:table collection="${aliasFrequencyDict}" />

we now have this:

<f:table collection="${aliasFrequencyDictList}" properties="['frequency','unit','description','lang']"/>

This, however, doesn't let me access any of the existing entries or add new ones, as I guess I'd have to manually specify these properties there, too. It doesn't seem like it's nearly as easy to explicitly state them in the edit view, for example, as it is in the index, though (or to make the editing actually work, on top of that).

EDIT2: Also, from what I gathered, using ROWID isn't a good idea anyway. Oracle docs state:

Although you can use the ROWID pseudocolumn in the SELECT and WHERE clause of a query, these pseudocolumn values are not actually stored in the database. You cannot insert, update, or delete a value of the ROWID pseudocolumn.

Thus, I'm out of ideas about how to progress :( Any help?

0

There are 0 best solutions below