Search code examples
oracle-databasehibernategrailsgrails-orm

New Grails domain class is not creating a table in the database


I just created a new grails domain class on a project I just started working on. I know the datasources are setup correctly since we already have a bunch of domain classes that are updating to the database just fine.

The error I get:

Caused by BatchUpdateException: ORA-00942: table or view does not exist

I tried running DBMUpdate but that also did not create the table.

Is there something I'm missing with creating domain classes? Do I need to change something in the changelog ? Any advise would be helpful!


Solution

  • The easiest thing would be to add dbCreate = "update" to your DataSource.groovy. A better thing would be to use the database-migrations plugin for your app.

    Regarding manually creating tables, the convention grails following by default is to underscore camelcase. For example, given the following domains:

    class User {
      String firstName
      String lastName 
      static hasMany = [addresses: Address]
    }
    
    class Address {
    
      static belongsTo = [user: User]
    }
    

    You would end up with the following tables:

    user
    ---------
    id
    version
    first_name
    last_name
    ---------
    
    address
    ---------
    id
    version
    user_id
    ---------