Note that there are some explanatory texts on larger screens.

plurals
  1. POGrails Spring Security Plugin - ONE-TO-ONE association with User domain
    primarykey
    data
    text
    <p>I'm using Spring Security Plugin to manage membership and authentication in my Grails app.</p> <p>I'm trying to associate the User domain class with a Profile domain by a one-to-one association.</p> <p>I added these line on User.groovy:</p> <pre><code>static hasOne = [userProfile:UserProfile] static constraints = { //... userProfile unique:true } </code></pre> <p>and to UserProfile.groovy:</p> <pre><code>User user </code></pre> <p>Alas, I had error when invoking UseRole.create(user,role). </p> <p>There is some best practice on how to obtain the same functionality I'm looking for. In particular, I want to associate any user with one profile object to extend it.</p> <p>I want then also add one-to-many relations with posts and other table... </p> <p>Thanks best regards</p> <p>PS: I obtain this error:</p> <p>Configuring Spring Security UI ... 2011-03-08 12:18:51,179 [main] ERROR context.GrailsContextLoader - Error executing bootstraps: null java.lang.NullPointerException at $Proxy19.save(Unknown Source) at com.dromedian.xxxxx.security.UserRole.create(UserRole.groovy:32) at com.dromedian.xxxxx.security.UserRole$create.call(Unknown Source) at BootStrap$_closure1.doCall(BootStrap.groovy:20) at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:251) at grails.util.Environment.executeForEnvironment(Environment.java:244) at grails.util.Environment.executeForCurrentEnvironment(Environment.java:220) at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212) at grails.web.container.EmbeddableServer$start.call(Unknown Source) at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158) at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy) at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280) at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy) at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149) at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy) at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116) at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy) at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59) at RunApp$_run_closure1.doCall(RunApp.groovy:33) at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415) at gant.Gant$_dispatch_closure7.doCall(Gant.groovy) at gant.Gant.withBuildListeners(Gant.groovy:427) at gant.Gant.this$2$withBuildListeners(Gant.groovy) at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source) at gant.Gant.dispatch(Gant.groovy:415) at gant.Gant.this$2$dispatch(Gant.groovy) at gant.Gant.invokeMethod(Gant.groovy) at gant.Gant.executeTargets(Gant.groovy:590) at gant.Gant.executeTargets(Gant.groovy:589) Application context shutting down...</p> <p>The configuration is:</p> <p>User.groovy (domain class created by spring security plugin)</p> <pre><code> static hasOne = [userDetail:UserDetail] static constraints = { username blank: false, unique: true password blank: false userDetail unique:true } </code></pre> <p>UserDetail.groovy</p> <pre><code>static hasOne = [user:User] static belongsTo = User </code></pre> <p>BootStrap.groovy</p> <pre><code> //TODO temporary added - no for production or persistent db def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true) def userRole = new Role(authority: 'ROLE_USER').save(flush: true) String password = springSecurityService.encodePassword('password') def testUser = new User(username: 'me', enabled: true, password: password) testUser.save(flush: true) if(testUser != null){ UserRole.create testUser, adminRole, true } </code></pre> <p>If I don't call</p> <pre><code> UserRole.create testUser, adminRole, true </code></pre> <p>there is no error. I tried to debug, but I can understand where is the error.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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