Package bookjpa

Examples of bookjpa.Book


        throws IOException {
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        EntityManager em = EMF.get().createEntityManager();
        Book book = new Book();
        book.setTitle("The Grapes of Wrath");
        book.setAuthor("John Steinbeck");
        book.setCopyrightYear(1939);
        Date authorBirthdate =
            new GregorianCalendar(1902, Calendar.FEBRUARY, 27).getTime();
        book.setAuthorBirthdate(authorBirthdate);
        try {
            em.persist(book);
        } finally {
            em.close();
        }

        // Because we're asking for a system-assigned ID in the key,
        // we can't access the Book's key until after the
        // EntityManager has closed and the Book has been saved.  For
        // this example, we allow an exception thrown by the datastore
        // to propagate to the runtime environment and assume that if
        // we got here the Book was saved properly.
        out.println("<p>Added a Book entity to the datastore via JPA, key: " +
                    KeyFactory.keyToString(book.getKey()));

        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
        fmt.setTimeZone(new SimpleTimeZone(0, ""));
        out.println("<p>The time is: " + fmt.format(new Date()) + "</p>");
    }
View Full Code Here

TOP

Related Classes of bookjpa.Book

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.