Advertisement
oquidave

jdo query problem

Nov 2nd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. public String getEmployee() {
  2.        
  3.         String returnRes = null;
  4.    
  5.         Query q = pm.newQuery(Employee.class);
  6.         q.setFilter("lang == langParam");
  7.         q.setOrdering("name");
  8.         q.declareParameters("String langParam");
  9.        
  10.         try {
  11.             List <Employee> results = (List<Employee>) q.execute("java");
  12.             if (! results.isEmpty()) {
  13.                 for (Employee employee : results) {
  14.                     returnRes = employee.getLang();
  15.                    
  16.                 }
  17.             } else {
  18.                 returnRes = "nothing to return";
  19.             }
  20.             return returnRes;
  21.            
  22.         } finally {
  23.             // TODO: handle exception
  24.             q.closeAll();
  25.             pm.close();
  26.         }
  27.        
  28.     }
  29.  
  30.  
  31. //Employee.java
  32.  
  33. package com.versefeed.setup;
  34.  
  35. import javax.jdo.annotations.IdGeneratorStrategy;
  36. import javax.jdo.annotations.NotPersistent;
  37. import javax.jdo.annotations.PersistenceCapable;
  38. import javax.jdo.annotations.Persistent;
  39. import javax.jdo.annotations.PrimaryKey;
  40.  
  41. import com.google.appengine.api.datastore.Key;
  42.  
  43. @PersistenceCapable
  44. public class Employee {
  45.    
  46.     @PrimaryKey
  47.     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  48.     private Key key;
  49.  
  50.     @Persistent private String name = "david";
  51.     @Persistent private String lang = "java";
  52.     @NotPersistent private int age = 26;
  53.    
  54.     //@Persistent private ContactInfo contactInfo;
  55.    
  56.     public Employee(String name, String lang) {
  57.         this.name = name;
  58.         this.lang = lang;
  59.     }
  60.    
  61.    
  62.     public String getName() {
  63.         return name;
  64.     }
  65.  
  66.     public void setName(String name) {
  67.         this.name = name;
  68.     }
  69.  
  70.     public String getLang() {
  71.         return lang;
  72.     }
  73.  
  74.     public void setLang(String lang) {
  75.         this.lang = lang;
  76.     }
  77.  
  78.     public int getAge() {
  79.         return age;
  80.     }
  81.  
  82.     public void setAge(int age) {
  83.         this.age = age;
  84.     }
  85.  
  86.     public Key getKey() {
  87.         return key;
  88.     }
  89.  
  90.    
  91.  
  92. }
  93.  
  94. //stacktrace
  95. WARNING: /persistpojo
  96. java.lang.NullPointerException
  97.     at com.versefeed.setup.PersistPojo.getEmployee(PersistPojo.java:45)
  98.     at com.versefeed.setup.PersistPojo.doGet(PersistPojo.java:78)
  99.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
  100.     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement