Hi everyone,
I am trying to get a simple DAO working to retrieve an object for a given id.
I found the below example and have been able to get it to work for my test app. The problem is the method "find" from the type session is deprecated. I haven't been able to find a solution.
Code:
public Geometry findById(Integer id) {
Object object = null;
Session session = null;
try {
session = sessionFactory.openSession();
List objects =
session.find(
"select g from " + Geometry.class.getName() + " as g where g.id = ?",
new Object[] { id },
new Type[] { Hibernate.INTEGER });
if (objects != null && !objects.isEmpty()) {
object = (Object) objects.get(0);
}
} catch (Exception e) {
System.out.println("Error occurred while reading by ID: " + e);
} finally {
if (session != null) {
try {
session.close();
} catch (Exception e) {
System.out.println("Error occurred while closing session: " + e);
}
}
}
return (Geometry)object;
}
To get this example to work I inserted the following imports
import org.hibernate.classic.Session;
import org.hibernate.type.Type;
If you can help please post your suggestions, I look forward to hearing from you.
Thanks, Alyssa.