Can you post a stack trace? It's not helpful if we don't know what line of
code is causing the exception.

On Mon, Feb 15, 2010 at 11:53 PM, sujata pagar <suja.paga...@gmail.com>wrote:

> Dear all,
>    I am getting NullPointerException in the following code for the
> transaction tx. Please reply me soon.
>
> Code:
>
> package com.wissen.enterprisebysush.
> server;
>
> import java.util.List;
>
> import javax.jdo.JDOHelper;
> import javax.jdo.PersistenceManager;
> import javax.jdo.PersistenceManagerFactory;
> import javax.jdo.Transaction;
> import javax.persistence.EntityManager;
> import javax.persistence.EntityManagerFactory;
> import javax.persistence.EntityTransaction;
> import javax.persistence.Persistence;
> import javax.persistence.Query;
>
> import com.google.gwt.user.client.Window;
> import com.google.gwt.user.server.rpc.RemoteServiceServlet;
> import com.wissen.enterprisebysush.client.GreetingService;
> import com.wissen.enterprisebysush.server.domainobject.Department;
> import com.wissen.enterprisebysush.server.domainobject.Employee;
>
> /**
>  * The server side implementation of the RPC service.
>  */
> @SuppressWarnings("serial")
> public class GreetingServiceImpl extends RemoteServiceServlet implements
> GreetingService {
>
>     EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("transactions-optional");
>
>     public String greetServer(String input) {
>         String serverInfo = getServletContext().getServerInfo();
>         String userAgent = getThreadLocalRequest().getHeader("User-Agent");
>         return "Hello, " + input + "!<br><br>I am running " + serverInfo +
> ".<br><br>It looks like you are using:<br>" + userAgent;
>     }
>
>     @SuppressWarnings("unchecked")
>     public void addDept(String dept_name, String dept_head) {
>
>         EntityManager em = null;
>
>         try {
>             em = emf.createEntityManager();
>             em.getTransaction().begin();
>             Department d = new Department();
>             d.setDept_name(dept_name);
>             d.setHead(dept_head);
>
>             Query q = em.createQuery("select from
> com.wissen.enterprisebysush.server.domainobject.Department d");
>             List<Department> deptList = q.getResultList();
>
>             for (Department dept : deptList) {
>                 System.out.println("Department name: " +
> dept.getDept_name());
>             }
>
>             em.persist(d);
>
>         } finally {
>             em.getTransaction().commit();
>             em.close();
>
>         }
>
>     }
>
>     public void addEmp(String emp_name, String emp_sal, String did) {
>         EntityManager em = emf.createEntityManager();
>         try {
>
>
>             String s = did;
>
>             EntityTransaction transaction = em.getTransaction();
>             transaction.begin();
>             System.out.println("value of Department_name is::" + s);
>             System.out.println("Transaction is active and
> is::"+transaction);
>
>             //            Query q = em.createQuery("select dept_id from
> com.wissen.enterprisebysush.server.domainobject.Department d where
> d.dept_name = ?1");
>             //            q.setParameter(1, s);
>             //            System.out.println("Name of Department is::" +
> s);
>             //            Department dept = (Department)
> q.getSingleResult();
>
>             Query q = em.createQuery("select from
> com.wissen.enterprisebysush.server.domainobject.Department d");
>             Department dept = (Department) q.getResultList().get(0);
>             System.out.println("Name of Department is::" +
> dept.getDept_name());
>
>             //System.out.println("Query executed
> Successfully!!!!!!!!!!!!!!" + q.getSingleResult());
>             Employee e = new Employee();
>             e.setEmp_name("Ritesh Navandar");
>             e.setEmp_sal("5000");
>             e.setDepartment(dept);
>             em.persist(e);
>
>             System.out.println("Transaction: " + transaction);
>
>             transaction.commit();
>             em.close();
>
>         } catch (NullPointerException e) {
>             e.printStackTrace();
>             System.out.println("Exception::" + e.getCause());
>         } finally {
>
>         }
>     }
>
> }
>
>
> --
> Regards,
> Sujata...
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-j...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>



-- 
Ikai Lan
Developer Programs Engineer, Google App Engine
http://googleappengine.blogspot.com | http://twitter.com/app_engine

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-j...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to