Grails - BootStrap.groovy - null pointer issues

826 Views Asked by At

Having issues with BootStrap.groovy loading development data. Prior it had always loaded data, but now has stopped throwing the below error when running grails run-app.

Message: Validation Error(s) occurred during save():
- Field error in object 'spotlight.content.Profile' on field 'portfolio': rejected value  [null];

My 2 models are as follows;

class Portfolio {
   Profile profile

String portfolioName
String portdescrip
Integer portpublished
Date dateCreated
Date lastUpdated

AND

class Profile {
   static belongsTo = [portfolio: Portfolio]

String portfoliohtml
String portfolioEmail
String portfoliocc
String portfolioAdmin
String portfolioFilestore
String portfolioColor
String bugzillaproduct
String bugzillacomponent
String rtqueue
String teamqueueemail
String etherpadurl
Integer siteupload
Date dateCreated
Date lastUpdated

Within the BootStrap.groovy file I have the following;

import java.util.Date;
import spotlight.content.Profile
import spotlight.content.Portfolio

class BootStrap { 

def init = { servletContext ->

    def profile = new Profile(portfoliohtml:"No",
            portfolioEmail: "[email protected]",
            portfolioAdmin:"Ian Neilsen",
            bugzillaproduct:"bz prod name",
            bugzillacomponent:"comp name",
            siteupload:1,
            portfoliocc: "[email protected]",
            portfolioColor:"red",
            portfolioFilestore:"blah",
            rtqueue:"queue name",
            teamqueueemail:"[email protected]",
            etherpadurl:"http://url.com",
            ).save(failOnError: true)

    def portfolio = new Portfolio(portfolioName:"Portfolio 1",
                            portdescrip:"portfolio descrition field",
                            portpublished:1,
                            portfolio:profile).save(failOnError: true)

}

I have tried every incarnation of adding my profile object to the portfolio object without any luck. As I said previously this worked and has now stopped throwing the null error.

has got me stumped any ideas?

cheers

1

There are 1 best solutions below

1
On BEST ANSWER

It looks like you have several mistakes. One (but not causing the error message) is, that you try to add your profile instance to portfolio property of your portfolia instance. Portfolio has no property portfolio.

Regarding your errormessage, try following:

def portfolio = new Portfolio(portfolioName:"Portfolio 1", ...)
portfolio.profile = new Profile(...)
portfolio.save(failOnError: true)

For further reading, look at the Many-to-one and one-to-one (GORM) section of the grails docs.