Some context so that this question actually makes some sense.
I have a trait from which I extend a case class and an object. I have a method that pattern matches to decide which to pull based on given conditions. When I pattern match and get the case class, everything works fine. But when I pattern match and get the object, an error is thrown.
Within the trait, I have methods that call the DB. And I also have vals that need overriding.
The curious thing is the error that is thrown when it the object is instantiated, is a DB specific error
java.sql.SQLInvalidAuthorizationSpecException: (conn=41) Transaction characteristics can't be changed while a transaction is in progress
Which led me on wild goose chase to hunt down whether the code was opening up another session unknowingly etc. But having checked my code, I knew I was passing around the one DB connection I had started and there wasn't any strange behaviour.
I figured, since my case class instance works, I wanted to see if converting my object into a case class would change anything.
Having converted my object to a case class, I then got an NPE error thrown which pointed me directly to the errant line of code that was causing problems. I then changed my vals to def in the trait and everything works fine.
So my questions is: Why is it that when I converted the object to the case class, it then threw up the error that was the true culprit. Which is why I asked the question: how is a case class vs object instantiated? Because I suspect this was the cause of the misleading error being thrown.
Feel free to correct my assumption if it is wrong.