6

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!

tim_yates
  • 167,322
  • 27
  • 342
  • 338
Brandon Wagner
  • 893
  • 9
  • 27

2 Answers2

6

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
---------
Gregg
  • 34,973
  • 19
  • 109
  • 214
  • Thank you, turns out the application was using the database-migration plugin so I just generated a changelog file using dbm-generate-gorm-changelog changelog.groovy and then ran dbm-update and all tables were created. Thanks! – Brandon Wagner Jul 09 '13 at 17:21
4

Try running...

grails export-schema

This will uses Hibernate's SchemaExport tool to generate DDL or export the schema for the entire database. From that file, you can grab the lines for the missing table.

Check out the Grails Quick Reference for more details on the command.

GeoGriffin
  • 1,065
  • 11
  • 26
  • 1
    Using grails version 3.2.8, the correct command is `grails schema-export` (I ran the command and it gave me this suggestion) – coderatchet Apr 24 '17 at 01:27