From one to many relationships in java google ap engine caused an error?

I have a system for saving user information. So, I have aggregation in my class, so the user class has a list from the contacts class ... etc. on the first page, "test it only to register the user by phone number", which should save the user in the database, but this causes an error when I deploy my project to the Google app engine < Server 500 error >

and another page - to update an existing user that was previously registered, so add to the list that has a user object.

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 causes registration for the user test, will receive the user's phone number, and registration should create a new user with this number the test page

 @SuppressWarnings("serial") 

The 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>"); } } 

enter the number on this page to create a 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(); } } } 

to continue updating the value in a user object that already exists

  @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 causing the error, and no value will be saved when the application 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 earlier as the user's phone number.

So how can I deal with lists and aggregation issues?

an error occurred while updating user information

 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) 
0
source share
1 answer

request problem

change this value

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

to

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

You do not select any columns. which cause sql syntax error

-1
source

All Articles