public static Employee getEmp(String name){
List<Employee> lst=null;
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
Query query=pm.newQuery(Employee.class);
query.setFilter("Name == NameParam");
query.declareParameters("String NameParam");
lst = (List<Employee>)query.execute(name);
lst.size();
} catch (JDOObjectNotFoundException e) {
pm.close();
return null;
}finally{
pm.close();
}
if(lst.isEmpty())
return null;
return lst.get(0);
}In the above function the employee with the name provided as the parameter will be returned. The Name field is not a primary key hence i used the Query to fetch the result. Since the query.execute() function returns the result of type List<Employee> i have to use many lines of coding. Is there any other way to fetch a single result i.e a result of type Employee not List<Employee> using the query object ? -- You received this message because you are subscribed to the Google Groups "Google App Engine" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.
