Hi,I was developed a simple JPA web application in google app engine to 
create a employee entity.But its not showing any entities in Datastore.Can 
anyone help me please(i fallowed 
https://developers.google.com/appengine/docs/java/datastore/jpa/overview).

Employee.java

package com.ravi.app;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity

public class Employee {
private int eid;
private String ename;
@Id
public int getEid() {
return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
}


ServletClass

package com.ravi.app;

import java.io.IOException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class RaviServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("texthtml");
resp.getWriter().println("Hello, world");

EntityManagerFactory emf = 
Persistence.createEntityManagerFactory("transactions-optional");
    EntityManager em = emf.createEntityManager();
    EntityTransaction tx=em.getTransaction();
    em.getTransaction().begin();
Employee e=new Employee();
int i=Integer.parseInt(req.getParameter("eid"));
String name=req.getParameter("ename");
e.setEid(i);
e.setEname(name);
em.persist(e);
 tx.commit();
em.close();
}
}

persistence.xml in web-->meta-inf-classes-->persistence.xml

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"; 
version="1.0">

    <persistence-unit name="transactions-optional">
        
<provider>org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider</provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" 
value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
        </properties>
    </persistence-unit>

</persistence>

web.xml

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns="http://java.sun.com/xml/ns/javaee";
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"; version="2.5">
<servlet>
<servlet-name>Ravi</servlet-name>
<servlet-class>com.ravi.app.RaviServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Ravi</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
</welcome-file-list>
</web-app>

</persistence>


login.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
<!-- above set at the top of the file will set     -->
<!-- the browser's rendering engine into           -->
<!-- "Quirks Mode". Replacing this declaration     -->
<!-- with a "Standards Mode" doctype is supported, -->
<!-- but may lead to some differences in layout.   -->

<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Hello App Engine</title>
  </head>

  <body>
    <h1>Hello App Engine!</h1>
    <center>
    <form name="login" method="get">
    Userid<input type="text" name="eid"><br>
Username<input type="text" name="ename"><br>
<input type="submit" value="Go">
</form>
</center>
      </body>
</html>



-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-appengine/-/HQkQ-YpJScIJ.
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.

Reply via email to