0

我已经实现了一个系统来保存有关用户的信息。所以我在我的班级有聚合所以用户类有来自联系人类的列表......等等在第一页“测试它只是为了通过电话号码注册用户”必须将用户保存在数据库中但是这会导致错误当我在 Google 应用引擎中部署我的项目 < 500 服务器错误>

另一个页面用于更新先前已注册的现有用户,因此这将添加到用户对象拥有的列表中。

用户类

@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);   }
     }

接触类

    @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; }

此页面原因注册用户测试将获取用户电话号码并注册应使用此号码 测试页面创建新用户

@SuppressWarnings("serial")

公共类测试扩展 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>");

    }
}

本页取号创建用户

@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();

        } }  }

此页面继续更新已经存在的用户对象的值

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

}

此页面用于保存导致错误的信息,并且不会在应用引擎中保存任何值

    @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(); }  }

这个111用于测试,我之前输入的用户电话号码。

那么我该如何处理列表和聚合问题呢?

当要更新用户信息时发生此错误

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)
4

1 回答 1

-1

查询中的问题

改变这个

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

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

您没有选择任何列。导致 sql 语法错误

于 2012-07-15T18:20:35.803 回答