Grails: what does .save (flush: flush: insert: true) do differently than .save (flush: true)

In the spring class with UserRole or SecUserSecRole security protection (you can call it whatever you choose), there is a command to make new UserRole() and save it with .save(flush:flush, insert:true)

What does it mean? What does it do otherwise than .save (flush: true)?

+4
source share
2 answers

From Grails docs :

Insert (optional) - if set to true, this will force Hibernate to execute SQL INSERT, it is useful in certain situations when outdated databases (for example, AS / 400), and Hibernate cannot determine whether to do INSERT or UPDATE

+5
source

People usually use flush () because they are not comfortable working with Hibernate.

If you need to know more about this, check this out http://blog.springsource.com/2010/06/23/gorm-gotchas-part-1/

Sometimes you need, in particular, when you are working in the same thread as the save () call, and you need to be sure that the domain object is stored in the database. In addition, some restrictions in your domain use a database to validate data. Sometimes you need to make sure that validation works. Here is an example of this:

http://johnrellis.blogspot.com/2009/09/grails-constraints-across-relationships.html

So, in principle, you should only use flash, if you really need something in the database RIGHT NOW! It is less than you think. I hope this help, and not a single bit of humor in the conversation about painting ... were so proud :)

URL: http://grails.1312388.n4.nabble.com/When-to-use-domain-save-flush-true-or-domain-save-td2289869.html

+4
source

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


All Articles