0

I've been spending the last couple of days just trying to get a barebones version of a Grails project to run. After moving through various problems dealing with Java version incompatibilities and buggy IDEs I can see the home stretch! But this last problem has me vexed.

My grails 2.4.4 project is using H2 and I'm running the application in Dev mode. I get a bunch of error messages like this:

Error | 2015-09-27 00:22:16,096 [localhost-startStop-1] ERROR hbm2ddl.SchemaExport - Table "ORDER_DELIVERY" not found; SQL statement: alter table order_delivery drop constraint FK_syi9a9vft4d15lq78cx3e1m38 if exists [42102-176]

I thought maybe these errors were related to this: Grails 2.4 and hibernate4 errors with run-app and that I could just ignore them. But when I got the dbconsole of my app it show no tables whatsoever. With that being said it seemed to be the problem described in this question:

Grails throws Table "xxx" not found

But I tried the accepted solution of using disk space and that has not solved the problem. Any ideas? I'm using Spring Security and Spring security with rest though disabling it hasn't helped.

from my Datasource.groovy:

environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:C:/temp/app_data;MVCC=TRUE"
        }
    }
}

My bootstrap class. SecUser and SecRole were generated by the s2 quickstart script, and my User domain extends SecUser. The User.findAll() command returns an empty list:

class BootStrap {

    def init = { servletContext ->
        User user = new User(username: "test", password: "test123", 
            email: "test@guy.com", name: "Dakota Roberts", title: "MD", active: true)
        user.save()

        SecRole roleUser = new SecRole(authority: "ROLE_USER")
        roleUser.save()

        new SecUserSecRole(user: user, role: roleUser).save()

        def users = User.findAll()
        for(User chkUser : users) {
            println chkUser.name
        }
    }
    def destroy = {
    }
}

User domain class example. It extends SecUser which sets tablePerHierarchy to false:

@Resource(uri="/user")
class User extends SecUser {
    String email
    String name
    String title
    Boolean active
    static belongsTo = [organization : Organization]
    static constraints = {
        email email: true, unique: true, blank: false
        name blank: false
    }
}
Community
  • 1
  • 1
IcedDante
  • 6,145
  • 12
  • 57
  • 100
  • Is your database file being created? If not try this for the connection: jdbc:h2:file:C:/temp/app_data;MVCC=TRUE – Emmanuel Rosa Sep 27 '15 at 15:21
  • Hey Emmanuel- it is being created. Three files are in my temp dir – IcedDante Sep 27 '15 at 15:23
  • Does it work with an in-memory H2 db? – Emmanuel Rosa Sep 27 '15 at 15:48
  • I don't follow you... I am using an in-memory H2 db as you can see in the datasource config. – IcedDante Sep 27 '15 at 15:52
  • Your datasource.groovy shows a file-based H2 db. An in-memory connection would look like this: jdbc:h2:mem:app_data – Emmanuel Rosa Sep 27 '15 at 15:59
  • Ah, I understand. Yes, I started with an in-memory and switched to file based to see if that would fix the problem. Neither worked – IcedDante Sep 27 '15 at 16:00
  • 1
    If you don't have any tables your domain.save()s should fail. Try doing your save()s in BootStrap.groovy like this: `domain.save(flush: true, failOnError: true)` I'm expecting an error that would provide a clue. – Emmanuel Rosa Sep 27 '15 at 17:59
  • I just realized something. When you checked the H2 database with the dbconsole, did the JDBC URL match the one in DataSource.groovy? – Emmanuel Rosa Sep 28 '15 at 19:14
  • I have this working now... unfortunately I'm not sure precisely what the source problem was so I just switched to mySql. I found the failOnError flag helpful and I was not aware of its existence. If you would like to add this comment as an answer I will accept it. – IcedDante Jan 11 '16 at 19:22

0 Answers0