svaret
svaret

Reputation: 335

Grails 2 and mongodb not working

I am using Grails 2.2.0 and MongoDB. I have configured Grails to run against MongoDB instead of the default H2 in memory database. From the error message h2 seems to be involved even though I think I removed it.

My DataSource.groovy:

grails { 
    mongo { 
        host = "localhost" 
        port = 27017 
        databaseName = "physicians" 
    } 
} 

My BuildConfig.groovy:

plugins { 
   runtime ":hibernate:$grailsVersion" 
   runtime ":jquery:1.8.0" 
   runtime ":resources:1.1.6" 

   // Uncomment these (or add new ones) to enable additional resources capabilities 
   //runtime ":zipped-resources:1.0" 
   //runtime ":cached-resources:1.0" 
   //runtime ":yui-minify-resources:0.1.4" 

   build ":tomcat:$grailsVersion" 

   runtime ":database-migration:1.1" 

   compile ':cache:1.0.0' 
   compile ':mongodb:1.1.0.GA' 
} 

The error I get when i want to save a domain object Artist is:

| Error 2013-01-03 22:33:18,881 [http-bio-9090-exec-1] ERROR util.JDBCExceptionReporter  - Table "ARTIST" not found; SQL statement: 
insert into artist (id, version, artist_name, birth_name) values (null, ?, ?, ?) [42102-164] 
| Error 2013-01-03 22:33:19,050 [http-bio-9090-exec-1] ERROR errors.GrailsExceptionResolver  - JdbcSQLException occurred when processing request: [GET] /musicstack/artist/ 
Table "ARTIST" not found; SQL statement: 
insert into artist (id, version, artist_name, birth_name) values (null, ?, ?, ?) [42102-164]. Stacktrace follows: 
Message: Table "ARTIST" not found; SQL statement: 
insert into artist (id, version, artist_name, birth_name) values (null, ?, ?, ?) [42102-164] 
    Line | Method 
->>  329 | getJdbcSQLException in org.h2.message.DbException 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    169 | get                 in     '' 
|    146 | get . . . . . . . . in     '' 
|   4753 | readTableOrView     in org.h2.command.Parser 
|   4731 | readTableOrView . . in     '' 
|    954 | parseInsert         in     '' 
|    375 | parsePrepared . . . in     '' 
|    279 | parse               in     '' 
|    251 | parse . . . . . . . in     '' 
|    217 | prepareCommand      in     '' 
|    415 | prepareLocal . . .  in org.h2.engine.Session 
|    364 | prepareCommand      in     '' 
|   1121 | prepareCommand . .  in org.h2.jdbc.JdbcConnection 
|     71 | <init>              in org.h2.jdbc.JdbcPreparedStatement 
|    267 | prepareStatement .  in org.h2.jdbc.JdbcConnection 
|   1051 | prepareStatement    in     '' 
|    508 | prepareStatement .  in org.apache.commons.dbcp.DelegatingConnection 
|    400 | prepareStatement    in org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper 
|      7 | index . . . . . . . in musicstack.ArtistController 
|    195 | doFilter            in grails.plugin.cache.web.filter.PageFragmentCachingFilter 
|     63 | doFilter . . . . .  in grails.plugin.cache.web.filter.AbstractFilter 
|    886 | runTask             in java.util.concurrent.ThreadPoolExecutor$Worker 
|    908 | run . . . . . . . . in     '' 
^    680 | run                 in java.lang.Thread 

What am I missing here?

Best regards /Lasse

====================================

Got it working.

First I had to remove the line

runtime ":hibernate:$grailsVersion" 

from the BuildConfig.groovy

When I did that I got this:

| Error Fatal error during compilation org.apache.tools.ant.BuildException: 
java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
(NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)

I then removed the line

runtime ":database-migration:1.1" 

from BuildConfig.groovy

This last part was not found when searching to solve this problem. Is this the way it is supposed to be done?

/Lasse

Upvotes: 2

Views: 1441

Answers (3)

Ben W
Ben W

Reputation: 2479

I had to remove Hibernate plugin from application.properties too for it to work. I am not sure why hibernate plugin was configured in application.properties

Upvotes: 1

coderLMN
coderLMN

Reputation: 3076

To use mongodb gorm stand alone in your project, you need to comment out

compile ':cache:1.0.0' 

in your BuildConfig, because cache plugin depends on hibernate. You can find it in the source code as:

    plugins {
        ....
        runtime(":hibernate:$grailsVersion") {
            export = false
        }
            ....
    }

Upvotes: 2

Nocmear
Nocmear

Reputation: 94

You had uninstalled the hibernate, so you need another plugin about mongodb. you cound add a line

compile ':mongodb:1.0.0.GA'

from BuildConfig.groovy instead of

runtime ":hibernate:$grailsVersion"

Upvotes: 0

Related Questions