Technology

Don’t release the app module yet!


I was well on my way to a new record in creating and deploying a web-service using Oracle ADF tooling when a bug hit me!

No matter what I did the View Object instance within the AM would be null. So for example, I was testing the web-service implementation class as a Java main, creating an instance of the Application Module and invoking a method I’d written to insert data into a table using an updatable VO. But the VO was always null! What gives?

I initially thought this was a datasource config issues, because it could not have been something related to initializing the AM (since I could step in the method in the AM, so I actually had the right config name and AM name passed). I did a “getTransaction()” within the AM and printed out the datasource url, userid etc. If those parameters were null I might be on the right track.

But no! Looks like I had the right data-source. So how is it possible that you have the right connection in the App Module, you can debug and step into a method in the AM and still if you did a “getViewObject(“”)” you got null? And mind you … the same method works fine when testing through a Data Bound JSF page (i.e. the same method is there with the methods in its signature as the Form fields).

It turns out the error was in the way I was obtaining the AM and using Java’s try/catch/finally blocks. So the intent was to release the AM when done, however the way I had implemented it was something like this:

private MyAppModule getAM() {
  MyAppModule am = null;
  try{
     am = Configuration.createNew ...
  }catch(Exception e){
     //handle am instantiation exceptions
  } finally{
     Configuration.release ....
  }
return am;
}

As you can see the intent was to release the AM if there was an exception and by throwing the release in the finally block, I was releasing it before returning it and doing so ALWAYS! BAD Thing to do : ) …this caused the AM to be not null, so you could step into it and it had a valid DB connection but was not registered as a part of the config framework (had been released), hence it could not create/find that VO we asked for by name.

Developer error 101! It worked after I moved the “Configuration.release ” bit to a different method. Now, I had to explicitly releast the AM from my Web Service Impl class from each WS method when I was done using the AM.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s