Page 1 of 1

SR17 JournalSet.iSave issue

PostPosted: Tue Oct 17, 2023 5:27 pm
by neil.interactit
Hi guys,

I am upgrading a client to Version 07.02.01.00 SR17 (from SR13).

A failure has arisen in a REST API Custom Routes plugin implementation. This has been updated with the using (var manager = this.Request.GetManager()) change due to the updated REST API plugin, and testing shows the manager appears to be being created successfully.

The error is:
Object reference not set to an instance of an object.
at JiwaFinancials.Jiwa.JiwaODBC.database.BeginNewTransaction(IsolationLevel IsolationLevel)
at JiwaFinancials.Jiwa.JiwaODBC.database.BeginNewTransaction()
at JiwaFinancials.Jiwa.JiwaJournalSets.JournalSet.iSave()
at JiwaFinancials.Jiwa.JiwaApplication.BusinessLogic.Maintenance.Save()
as a result of executing a
Code: Select all
   journalSet.Save();


journalSet is created with:
Code: Select all
private JournalSet GetOrCreateJournalSet(Manager manager, string description, DateTime postedDate)
{
   var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
   var results = Db.SqlList<GL_Sets>("SELECT TOP 1 * FROM GL_Sets WHERE Description = @Description AND SetType = 2 AND PostDateTime = @PostDateTime", new { Description = description, PostDateTime = postedDate });
   if (results.Any())
      journalSet.Read(results.First().GLSetID);
   else
   {
      journalSet.CreateNew();
      journalSet.Description = description;
      journalSet.PostedDate = postedDate;
      journalSet.Source = "Local";
      journalSet.SetType = JournalSet.SetTypes.Pending;
   }
   return journalSet;
}

Then has lines added via:
Code: Select all
   var journalLine = manager.CollectionItemFactory.CreateCollectionItem<Line>();
   ...
   journalSet.Lines.Add(journalLine);

I can't spot anything else significant. This works for SR13 (with the older REST API plugin).

Is this enough detail for you to see how I am incorrectly instantiating journalSet and/or journalLine for SR17, or something else I am missing that is now needed?

Cheers,
Neil.

Re: SR17 JournalSet.iSave issue

PostPosted: Wed Oct 18, 2023 7:05 am
by SBarnes
Hi Neil,

It's probably better that you post the entire plugin rather than snippets as then it would be possible to run it through the debugger and see what is going on.

The other way of going is of course you could actually call the Jiwa routes themselves for journals by filling in the dto request objects for either post or patch on a journal and then calling post or patch on the journal service, if you look in the rest api you should be able to figure out the service class and then you can use ServiceStack's ResolveService call to get the class look at this link on how to do it https://stackoverflow.com/questions/238 ... ntent-type

Re: SR17 JournalSet.iSave issue

PostPosted: Wed Oct 18, 2023 10:28 am
by neil.interactit
Thanks Stuart.

I created a new RestApiFailingJournalSetSaveMinimal plugin with a single route and just the JournalSet create and save. AND IT WORKED. Bummer.

So I will progressively add more in from the failing plugin code and should be able to work out the issue.

I'll update this thread either with what the fix was, or a failing plugin sample.

Cheers,
Neil

Re: SR17 JournalSet.iSave issue

PostPosted: Wed Oct 18, 2023 10:33 am
by Mike.Sheen
neil.interactit wrote:I created a new RestApiFailingJournalSetSaveMinimal plugin with a single route and just the JournalSet create and save. AND IT WORKED. Bummer.


That is excellent news!

Re: SR17 JournalSet.iSave issue  Topic is solved

PostPosted: Thu Oct 19, 2023 8:52 am
by neil.interactit
Mike nailed this offline for me.

In case it helps others ...

Any Jiwa server release upgrade from before SR15 to on or after SR15 involves breaking changes for REST API based plugins per https://jiwa.atlassian.net/wiki/spaces/J7UG/pages/9863169/Jiwa+7.02.01.00+Service+Release+15#BreakingChanges ...
Code which was like this:
Code: Select all
JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this.GetManager();
// other service method code in here

Needs to change to this:
Code: Select all
using(JiwaFinancials.Jiwa.JiwaApplication.Manager manager = this.Request.GetManager())
{
  // other service method code in here
}


In my case the change (vastly simplified) was from:
Code: Select all
JournalSet journalSet = null;
var manager = this.Request.GetManager();
var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
journalSet.Save();

To:
Code: Select all
JournalSet journalSet = null;
using (var manager = this.Request.GetManager())
{
   var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
}
journalSet.Save();

What I missed, that is not visually apparent, is that the BusinessLogicFactory passes manager into journalSet causing the error on Save as manager is disposed by then.

The solution was:
Code: Select all
JournalSet journalSet = null;
using (var manager = this.Request.GetManager())
{
   var journalSet = manager.BusinessLogicFactory.CreateBusinessLogic<JournalSet>(null);
   journalSet.Save();
}

Thanks Mike!

Cheers,
Neil

Re: SR17 JournalSet.iSave issue

PostPosted: Thu Oct 19, 2023 9:31 am
by SBarnes
Hi Neil,

Yeah the the best thing to do going forward is create the manager in a using clause that surrounds all other code with its braces.