I am trying to write an accessor class for Hibernate using Java Generics. What I would like to write is something like this:
List<DataClass> dataList = (List<DataClass>) session.find(
"from " + this.classObj.getName() + " as objclass where objclass." + this.realKeyName + " = ?",
key, Hibernate.entity(key));
But Hibernate.entity doesn't work for simple key types like String, so instead I have to do this:
List<DataClass> dataList = (List<DataClass>) session.find(
"from " + this.classObj.getName() +
" as objclass where objclass." + this.realKeyName + " = '" + key +"'");
Is there any way to dynamically determine the correct Hibernate type other than write my own function to do the mapping?
|