Examples of BookReview


Examples of relationships.BookReview

            book.setBookCoverImage(new BookCoverImage());
            book.getBookCoverImage().setType("image/jpg");

            List<BookReview> bookReviews = book.getBookReviews();
            BookReview bookReview = new BookReview();
            bookReview.setRating(5);
            bookReviews.add(bookReview);
            bookReview = new BookReview();
            bookReview.setRating(4);
            bookReviews.add(bookReview);

            EntityTransaction txn = em.getTransaction();
            txn.begin();
            try {
                // When the Book is made persistent, the "PERSIST"
                // action cascades to the BookCoverImage object and
                // all BookReview objects.
                em.persist(book);
                txn.commit();
            } finally {
                if (txn.isActive()) {
                    txn.rollback();
                }
            }

        } finally {
            em.close();
        }

        try {
            em = emf.createEntityManager();

            Book book = em.find(Book.class, "978-0141185064");
            if (book != null) {
                out.println("<p>Found <i>" + book.getTitle() + "</i></p>");

                // Automatically fetch the BookCoverImage entity and access a field.
                out.println("<p>Book cover image type: " + book.getBookCoverImage().getType() + "</p>");

                out.println("<p>Ratings: ");
                for (BookReview bookReview : book.getBookReviews()) {
                    out.println("[" + bookReview.getRating() + "] ");
                }
                out.println("</p>");

            } else {
                out.println("Could not find that book I was looking for...");
View Full Code Here

Examples of transactions.BookReview

            EntityTransaction txn = em.getTransaction();
            txn.begin();
            try {
                Book book = em.find(Book.class, "978-0596522728");
                BookReview bookReview = new BookReview();
                bookReview.setRating(5);
                book.getBookReviews().add(bookReview);

                // No need to explicitly persist() the BookReview
                // because it is a field of Book.
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.