Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: dbconsole isn't showing my domain classes

Tags:

grails

h2

On this fine blog it says that in dbconsole I should be able to see little icons on the left for my tables like how he sees "BOOK". http://www.redtoad.ca/ataylor/2011/11/h2-database-console-in-grails-2/

I'm using STS and grails 2.0, and I make an application with several domain classes (I can go to the controllers and see lists and stuff), but the dbconsole doesn't show any domain classes. Just goes straight into INFORMATION_SCHEMA.

Where are my domain classes? I can see lists and use .findBy and stuff!!

like image 722
Mikey Avatar asked Feb 14 '12 02:02

Mikey


2 Answers

You need to change the URL to what it says in your DataSource.groovy

URL should be changed in this initial screen. enter image description here

like image 147
Mikey Avatar answered Sep 19 '22 10:09

Mikey


Thank you, Mikey! I had the same problem! Indeed, look into

grails-app/conf/DataSource.groovy

At least in my case, JDBC URL can be set to jdbc:h2:mem:devDb for the development database, jdbc:h2:mem:testDb for the test database, and jdbc:h2:mem:prodDb for the production database.

The console has no way of knowing which one you prefer, so it defaults to test. Also, if you click on "JDBC URL" in the dbconsole mode in the browser, it shows you some tips. In particular, it explains that "The URL jdbc:h2:~/test means the database is stored in the user home directory in files starting with 'test'." Indeed, in my home directory I now have test.h2.db, test.lock.db, and test.trace.db. It also explains why the data is not persisted by default. Didn't you notice that with the default setup every time you restart Grails, you have to re-create all the objects? Well, this is because of the ":mem:" part in the JDBC URL.

This default probably has nothing to do with Grails; I would guess that H2 simply creates a test database in your home directory by default, unless otherwise stated. I would also imagine that you may have many different databases in a complicated production environment, and this is why Grails is not trying to guess what it is that you want.

Also see the official H2 documentation

like image 33
Sergey Orshanskiy Avatar answered Sep 19 '22 10:09

Sergey Orshanskiy