Correcting this ... ResultRepository.java " public class ResultRepository {
@Programmatic public Result create( final String description, final int simulationYear, final int status ) { final Result result = container.newTransientInstance(Result.class); result.setDescription(description); result.setSimulationYear(simulationYear); result.setStatus(status); return result; } } " 2017-04-06 12:20 GMT-04:00, L Eder <eder200...@gmail.com>: > Hi members of this forum: > > I have this situation - a Scenario entity comprised of many Result > entities. And vice-versa. > > I then add the first result to a sortedset, using Scenario.runScenario(). > > However when i add the second result object, in > Scenario.adjustResult(), the first one is overwritten. > > Thanks for any help on this issue, Eder > > ----------- > > Scenario.java > " > public class Scenario implements Comparable<Scenario> { > > public String title() { > return getDescription(); > } > > @Column(allowsNull = "false") > @Property() > @Getter @Setter > private String description; > > @Column(allowsNull = "false") > @Property() > @Getter > @Setter > private int simulationYear; > > @Column(allowsNull = "false") > @Property() > @Getter @Setter > private ModelCategory modelCategory; > > // @Property(hidden = Where.ANYWHERE) > @Column(allowsNull = "true") > @Property() > @Getter @Setter > private Result budget; > > @Persistent(table = "ScenarioResults") > @Join(column = "scenario_id") > // @Element(column = "res_id") > @Element(column = "result_id") > @Collection() > @Getter @Setter > @CollectionLayout(render = RenderType.EAGERLY) > private SortedSet<Result> actuals = new TreeSet<Result>(); > > .... > public Scenario importSeihan( > @Parameter(fileAccept = ".xlsx") > @ParameterLayout(named="Excel spreadsheet") > final Blob spreadsheet){ > .... > getBudget().getCords().add(qitem); > .... > } > > @Action() > public Result runScenario(){ > > getActuals().add(getBudget()); > > return getBudget(); > } > > @Action() > public Result adjustResult() { > Date dNow = new Date(); > SimpleDateFormat ft = > new SimpleDateFormat ("dd-MMMM-yyyy-HH:mm"); > > /*final*/ Result adj = getBudget(); > String descr = getDescription() + "_adjust_" + ft.format(dNow) > + "_[optional description]"; > adj.setDescription(descr); > adj.setStatus(AdjustStatus.valueOf("InProgress").ordinal()); > > getActuals().add(adj); > > return resultRepo.findByDescription(descr); > } > > > @Override > public int compareTo(final Scenario other) { > return org.apache.isis.applib.util.ObjectContracts.compare(this, > other, "description"); > } > > @Override > public String toString() { > return org.apache.isis.applib.util.ObjectContracts.toString(this, > "description"); > } > > @javax.inject.Inject > private ResultRepository resultRepo; > } > " > > > > ScenarioRepository.java > " > public class ScenarioRepository { > .... > @Programmatic > public Scenario create( > final String description, > final int simulationYear, > final ModelCategory modelcat) { > final TitleBuffer buf = new TitleBuffer(); > > Date dNow = new Date(); > SimpleDateFormat ft = > new SimpleDateFormat ("dd-MMMM-yyyy-HH:mm"); > > buf.append("SimYear-" + simulationYear + "_" + modelcat + > "_Created-"); > buf.append(ft.format(dNow) + "_"); > buf.append(description); > > final Scenario scenario = > container.newTransientInstance(Scenario.class); > scenario.setDescription(buf.toString()); > scenario.setSimulationYear(simulationYear); > scenario.setModelCategory(modelcat); > > scenario.setBudget( > resultRepository.create( > buf.toString() + " - Analysis Results", > simulationYear, > AdjustStatus.valueOf("Created").ordinal())); > > container.persistIfNotAlready(scenario); > return scenario; > } > > @Inject > ResultRepository resultRepository; > } > " > > > Result.java > " > public class Result implements Comparable<Result> { > > @Title > @Column(allowsNull = "false") > @Property(maxLength = 120) > @Getter @Setter > private String description; > > public String getDescription(){ > > return description; > } > > @Column(allowsNull = "false") > @Property() > @Getter @Setter > private int simulationYear; > > @Column(allowsNull = "false") > @Property() > @Getter @Setter > private int status; > > @CollectionLayout(render = RenderType.EAGERLY, named = "Power Cord") > private SortedSet<QuotaItem> cords = new TreeSet<QuotaItem>(); > > @Collection() > public SortedSet<QuotaItem> getCords() { > > return cords; > } > public void setCords( > final SortedSet<QuotaItem> obj) { > this.cords = obj; > } > > } > > > ResultRepository.java > " > public class ResultRepository { > > @Programmatic > public Result create( > final String description, > final int simulationYear, > final int status > ) { > final ComponentSeihan componentSeihan = > container.newTransientInstance(ComponentSeihan.class); > > componentSeihan.setDescription(description); > componentSeihan.setSimulationYear(simulationYear); > componentSeihan.setStatus(status); > return componentSeihan; > } > } > " > ---- >