java - Null Pointer Exception for Ebean Insert Query -
i have e bean model of table countries , indicators. indicators model looks this
public class indicators extends model { private static final long serialversionuid = 1l; @id public long id; @onetomany(mappedby = "indicator") public hashset<indicators> transactions; @manytoone @joincolumn(name = "countryid") public countries country; } and countries model looks this
public class countries extends model { private static final long serialversionuid = 1l; @id @column(name = "countryid") public long countryid; @onetomany(mappedby = "country") public hashset<countries> indicators; } and trying call insert function
private static void procm007_sp003(excelind excelrow, string indicator_code) { // insert indicators indobj = new indicators(); indobj.country.countryid=542l; indobj.save(); however, indobj.country.countryid causes null pointer exception.
any appreciated. :)
by default instance variables set null , have not initialized country variable of object indicators, null. , hence setting countryid on null object lead nullpointerexception.
you need initialize country attribute of indicators object also:
indicators indobj = new indicators(); indobj.country = new countries(); indobj.country.countryid = 542l; indobj.save();
Comments
Post a Comment