0

i have implement a system to save information about user . So i have aggregation at my class so the user class has list from contact class ...etc in the first page "test it's just for register the user just by phone number " that must save the user in database but this cause error when i deploye my project in Google app engine < 500 server error >

and the other page for update the exist user who previously has been registered, so at this will add to the list which the user object has .

user class

@PersistenceCapable
public class User implements Serializable{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

 @Persistent
public String userNumber;

 @Persistent (mappedBy = "userC")
 public List<Contact> UserContacts =new  ArrayList<Contact>();

 public void AddContact(String name,String number) {
     Contact C=new Contact();
     C.ContactName=name;
     C.PhoneNumber=number;
     this.UserContacts.add(C);   }
     }

Contact class

    @PersistenceCapable
public class Contact implements Serializable{
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

     @Persistent
        public String ContactName;

     @Persistent
    public String PhoneNumber;  
             @Persistent
    public User userC; }

this page cause register for the user test will get user phone number and sign up should create new user with this number test page

@SuppressWarnings("serial")

public class Test extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
        resp.setContentType("text/html");
        resp.getWriter().println("<html><body><form  method = \"POST\"     action=\"/signup\">" + "please enter ur number :"+"<h4><label>name :  <input name =  \"userphoneNUMBER\" type =  \"text \" size =  \"25 \" />  </label>"+"<p> <input type = \"submit\" value = \"Submit\" />"+ "</form></body></html>");

    }
}

this page take the number to create user

@SuppressWarnings("serial")
public class SignUP extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");
        String user_PhoneNumber=req.getParameter("userphoneNUMBER");
        User obj = new User();
    obj.userNumber=user_PhoneNumber;
    resp.getWriter().println(obj.userNumber );
        PersistenceManager pm = PMF.get().getPersistenceManager();

        try {
            pm.makePersistent(obj);
        } finally {
            pm.close();

        } }  }

this page to continue update value at user object who already exist

    @SuppressWarnings("serial")
public class Testinfo extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/html");
        resp.getWriter().println("<html><body><form  method = \"POST\" action=\"/saveinfo\">" +
                "<center> <h2>please fill this form :</h2> </br> "+
"<h4><label> ContactName :  <input name =  \"ContactName\" type =  \"text \" size =  \"25 \" />  </label>"
+
"<p> <input type = \"submit\" value = \"Submit\" />"+
                "</form></body></html>");
    }

}

this page to save the information which cause error and no value will save at app engine

    @SuppressWarnings("serial")
public class SaveInfo extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        resp.setContentType("text/plain");

        String ContactName = req.getParameter("ContactName");
        String ContactNumber = req.getParameter("ContactNumber");
                   PersistenceManager pm = PMF.get().getPersistenceManager();
        Query query = pm.newQuery("select from " + User.class.getName());
        List<User> list = (List<User>) query.execute();
        for (User obj : list) {


            if (obj.userNumber.equals("111")) {
                 pm.currentTransaction().begin();
                                     obj.AddContact(ContactName, ContactNumber);

                pm.makePersistent(obj);

                 pm.currentTransaction().commit(); }
            }
                          pm.close(); }  }

this 111 for testing which i entered before as user phone number .

So how can i deal with lists and aggregation issues ??

when going to update the user information this error occurred

Uncaught exception from servlet
javax.jdo.JDOUserException: Identifier expected at character 1 in "*" at         org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:375)
at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:230)
at sstooree.SaveInfo.doPost(SaveInfo.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
Hanaa
  • 87
  • 1
  • 2
  • 10
  • A "server error" would obviously be accompanied by a reason, stack trace etc. Keeping them secret won't help people suggest to you where your problem is – DataNucleus Jul 16 '12 at 06:56
  • this the error occurred 2012-07-15 14:16:11.786 /saveinfo 500 57ms 0kb Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 92.253.89.127 - - [15/Jul/2012:14:16:11 -0700] "POST /saveinfo HTTP/1.1" 500 0 "the url" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11" "myurl" ms=58 cpu_ms=19 api_cpu_ms=0 cpm_usd=0.000613 instance=00c61b117c530c9a537b0089084cba4cb66e15 W 2012-07-15 14:16:11.782 /saveinfo – Hanaa Jul 16 '12 at 07:25
  • javax.jdo.JDOUserException: Identifier expected at character 1 in "*" at org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:375) at org.datanucleus.jdo.JDOQuery.execute(JDOQuery.java:230) at sstooree.SaveInfo.doPost(SaveInfo.java:44) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) – Hanaa Jul 16 '12 at 07:26
  • So the query you used was wrong ... and that is not the full stack trace. The real exception is nested. So put it in your post not in the comments, and formatted so its readable. – DataNucleus Jul 16 '12 at 08:06
  • ok but i think the problem due to @Persistent(mappedBy = "otherclass") – Hanaa Jul 16 '12 at 08:14

1 Answers1

-1

the problem in the query

change this

Query query = pm.newQuery("select from " + User.class.getName());

to

Query query = pm.newQuery("select * from " + User.class.getName());

you are not selecting any column . which cause a sql syntax error

confucius
  • 13,127
  • 10
  • 47
  • 66