-1

AS I am new to JDO and datastore

I have set up a simple Google App Engine project based on Spring Framework to Perform Basic CRUD operation.

When I run my Application Its Show's

Persistent class "Class com.pandian.model.Customer does not seem to have been enhanced. You may want to rerun the enhancer and check for errors in the output." has no table in the database, but the operation requires it. Please check the specification of the MetaData for this class.

Customer

@PersistenceCapable
    public class Customer {

        @PrimaryKey
        @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
        private Key key;

        @Persistent
        private String name;

        @Persistent
        private String email;

        @Persistent
        private Date date;

        public Key getKey() {
            return key;
        }

        public void setKey(Key key) {
            this.key = key;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public Date getDate() {
            return date;
        }

        public void setDate(Date date) {
            this.date = date;
        }

        public Customer() {
            super();
        }

Controller

@Controller
@RequestMapping("/customer")
public class CustomerController {

    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public String getAddCustomerPage(ModelMap model) {

        return "add";

    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ModelAndView add(HttpServletRequest request, ModelMap model) {

        String name = request.getParameter("name");
        String email = request.getParameter("email");

        Customer c = new Customer();
        c.setName(name);
        c.setEmail(email);
        c.setDate(new Date());

        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(c);
        } finally {
            pm.close();
        }

        return new ModelAndView("redirect:list");

    }

    @RequestMapping(value = "/update/{name}", method = RequestMethod.GET)
    public String getUpdateCustomerPage(@PathVariable String name,
        HttpServletRequest request, ModelMap model) {

        PersistenceManager pm = PMF.get().getPersistenceManager();

        Query q = pm.newQuery(Customer.class);
        q.setFilter("name == nameParameter");
        q.setOrdering("date desc");
        q.declareParameters("String nameParameter");

        try {
            @SuppressWarnings("unchecked")
            List<Customer> results = (List<Customer>) q.execute(name);

            if (results.isEmpty()) {
                model.addAttribute("customer", null);
            } else {
                model.addAttribute("customer", results.get(0));
            }
        } finally {
            q.closeAll();
            pm.close();
        }

        return "update";

    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ModelAndView update(HttpServletRequest request, ModelMap model) {

        String name = request.getParameter("name");
        String email = request.getParameter("email");
        String key = request.getParameter("key");

        PersistenceManager pm = PMF.get().getPersistenceManager();

        try {

            Customer c = pm.getObjectById(Customer.class, key);

            c.setName(name);
            c.setEmail(email);
            c.setDate(new Date());

        } finally {

            pm.close();
        }

        // return to list
        return new ModelAndView("redirect:list");

    }

    @RequestMapping(value = "/delete/{key}", method = RequestMethod.GET)
    public ModelAndView delete(@PathVariable String key,
            HttpServletRequest request, ModelMap model) {

        PersistenceManager pm = PMF.get().getPersistenceManager();

        try {

            Customer c = pm.getObjectById(Customer.class, key);
            pm.deletePersistent(c);

        } finally {
            pm.close();
        }

PMF

public final class PMF {
    private static final PersistenceManagerFactory pmfInstance = JDOHelper
            .getPersistenceManagerFactory("transactions-optional");

    private PMF() {
    }

list//JSP

....
<%

        if(request.getAttribute("customerList")!=null){

            List<Customer> customers = 
                           (List<Customer>)request.getAttribute("customerList");

            if(!customers.isEmpty()){
                 for(Customer c : customers){

        %>
                <tr>
                  <td><%=c.getName() %></td>
                  <td><%=c.getEmail() %></td>

...

Any body help me out from this.....

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
user2742540
  • 45
  • 2
  • 7

1 Answers1

0

When you looked at the AppEngine docs for using JDO, you would have come across https://developers.google.com/eclipse/docs/appengine_orm

This tells you HOW to enhance classes for use with JDO.

DataNucleus
  • 15,497
  • 3
  • 32
  • 37