Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails 2.3.2: findOrCreate using Enums in Bootstrap
    text
    copied!<p>I am having troubles with using the findOrCreateBy method in the Bootstrap.groovy. </p> <pre><code>class Guest { String firstname String lastname Gender gender static constraints = { firstname blank: false lastname blank: false gender nullable: false } } enum Gender { MALE('male'), FEMALE('female') final String v Gender(String s) { v = s } } </code></pre> <p>And in the Bootstrap I try to create Guests if they do not exist yet.</p> <pre><code>Guest guest = Guest.findOrCreateByFirstnameAndLastnameAndGender(firstname, lastname, Gender.MALE) guest.save() </code></pre> <p>The first time I run the app against MySQL everything works fine. The apps starts without any error. If I run the app a second time (this time with guest in the database) I get the following failure.</p> <pre><code>| Error 2013-11-17 14:27:37,621 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Unknown name value [1] for enum class [ch.silviowangler.ch.cisposiamo.Gender] Message: Unknown name value [1] for enum class [ch.silviowangler.ch.cisposiamo.Gender] Line | Method -&gt;&gt; 105 | methodMissing in org.grails.datastore.gorm.GormStaticApi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 106 | createGuest in BootStrap | 102 | createGuest . . . . . . . . . . in '' | 66 | doCall in BootStrap$_closure1 | 308 | evaluateEnvironmentSpecificBlock in grails.util.Environment | 301 | executeForEnvironment in '' | 277 | executeForCurrentEnvironment . . in '' | 262 | run in java.util.concurrent.FutureTask | 1145 | runWorker . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor | 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker ^ 744 | run . . . . . . . . . . . . . . in java.lang.Thread </code></pre> <p>It seems the the first time Gorm writes values '0' and '1' to the database. In the second run it fails to convert these 0 and 1 into the corresponding enum value. Can anybody tell me what I am doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload