The main problem is enough, but its roots go deep within the framework (and there is little specific information on this topic), so I post it here to save others from pain (and make sure that I am right or wrong in my thinking).
What is the problem?
Grails automatically enters a Long id field into your domains ( see Beckwith comment ). When using the legacy DB Grails database, Longs to bigints uses an inefficient storage type by default that anyone who deals with large millions of record tables would avoid.
Having discovered this a few months ago, I started working on getting the “right” column type for my domain identifiers. Without Java background, blindly, I thought, “Long-bad”, “Integer-good” and “Configure hibernation dialogs” for “Integer” types for what I would do manually in mysql
registerColumnType (Types.INTEGER, 'mediumint unsigned')
and then defined "Integer id" in all my domains (not necessarily according to Burt's comment in the link above). Everything worked smoothly, perfectly, for other things.
Speed up to Grails 2.0 (since I couldn't resist all the pluses ;-)) and Spock. For life, I could not understand why, despite the 2.0 new GORMs in memory and support for dynamic crawlers, Domain.findByFoo (fooVal) always returns null (yes, I @Mock (Domain) and fills the test data). In fact, both within the test itself and for the purpose of @TestFor, the only GORM methods that worked were save () and get (); everything else is returned null.
I hacked the quick test application, domain + controller + spoc spec and found the source of the problem: if you use a property type other than Long for other identifiers (including links to FK), your @Mock domain will be useless.
So, can I fix or not say that I need to use Long ids to take full advantage of the framework? @Mock + @TestFor + Spock - an incredible combo! The guide was appreciated before I dropped the refactoring path to the end ...