Grails does not save my database data

I am building a small Grails application, and I am trying to keep the data between server restarts in the development environment.

I changed the corresponding part of DataSource.groovy to the following:

development { dataSource { dbCreate = "update" // one of 'create', 'create-drop','update' url = "jdbc:hsqldb:mem:devDB" } } 

Every time I restart the server, all data disappears. Am I missing another configuration?

I tried this with and without samples in BootStrap.groovy (if that matters).

+6
source share
3 answers

... try removing the "mem" part of your url: jdbc: hsqldb: devDB line. Now you run db in memory mode, therefore, losing data. Running db in native mode should do what you need.

+11
source

You use the database in memory, so there is no way to survive the data on a server reboot. Switch to a persistent database (MySQL, Postgres, etc.), then set dbCreate = 'validate'

For example, if you chose MySQL as the database, you would need to change the settings in DataSource.groovy to:

 development { dataSource { dbCreate = "validate" // Put the MySQL JDBC JAR on the classpath of your Grails app driverClassName = "com.mysql.jdbc.Driver" // Change these property values as needed url = "jdbc:mysql://localhost/yourDB" username = "yourUser" password = "yourPassword" } } 
+1
source

Your url is configured to use the database in memory. This is what β€œmem” means in your url string.

It gets easier for me, especially with a small project, using BootStrap.groovy in the combination w / dbCreate = "create-drop".

You can change your url to point to a file or relational database, though if you want to save w / out using BootStrap.groovy. I am using grails 2.0 w / an in db memory.

url = "jdbc: h2: db / devDb; auto_server = true"

Here is an example using mySql (if you have a jdbc driver for mysql):

url = "jdbc: mysql: // localhost: 8080 / foo? autoreconnect = true"

W / file example:

url = "jdbc: hsqldb: file: prodDb; shutdown = true"

Hope this helps.

+1
source

Source: https://habr.com/ru/post/898967/


All Articles