I'm starting on a Scala application which uses Hibernate (JPA) on the back end. In order to load an object, I use this line of code:
val addr = s.load(classOf[Address], addr_id).asInstanceOf[Address];
Needless to say, that's a little painful. I wrote a helper class which looks like this:
import org.hibernate.Session
class DataLoader(s: Session) {
def loadAddress(id: Long): Address = {
return s.load(classOf[Address], id).asInstanceOf[Address];
}
...
}
So, now I can do this:
val dl = new DataLoader(s)
val addr = dl loadAddress(addr_id)
Here's the question: How do I write a generic parametrized method which can load any object using this same pattern? i.e
val addr = dl load[Address](addr_id)
(or something along those lines.)
I'm new to Scala so please forgive anything here that's especially hideous.