Package javax.persistence

Examples of javax.persistence.EntityManager.persist()


        entityManager.getTransaction().begin();
        // creates a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // makes a rollback
        entityManager.getTransaction().rollback();
        entityManager.close();
        // verifies if the container made the rollback
        Book bookResult = entityManager.find(Book.class, new Integer(ID));
View Full Code Here


        entityManager.getTransaction().setRollbackOnly();
        // creates a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // verifies if the container registered the rollback.
        assertTrue(entityManager.getTransaction().getRollbackOnly(),
                "The transaction is marked as rollback, but the container returned false for the method getRollbackOnly()");

        // tries to make the commit, the container must throw an exception.
View Full Code Here

        entityManager.getTransaction().begin();
        // inserts a book
        Book book = new Book();
        book.setId(ID);
        book.setName(ENTITY_NAME);
        entityManager.persist(book);
        // verifies if the transaction is marked as ACTIVE
        assertTrue(entityManager.getTransaction().isActive(),
                "The transaction is active, but the container returned false when the method isActive was called.");
        // verify if the rollbackonly is not set.
        assertFalse(entityManager.getTransaction().getRollbackOnly(),
View Full Code Here

           
            String mode = req.getParameter("mode");
            if ("Write".equals(mode))
            {
               TestEntity test = new TestEntity("Hello", "World");
               em.persist(test);
            }
            else
            {
               TestEntity test = em.find(TestEntity.class, "Hello");
               resp.setContentType("text/plain");
View Full Code Here

            {
                Product p = new Product();

                EntityManager em = (EntityManager) getValue("#{entityManager}");
                try {
                    em.persist(p);
                    fail("empty product persisted");
                } catch (PersistenceException e) {
                    // good
                }                
            }           
View Full Code Here

         new FacesRequest() {
            protected void invokeApplication()
            {
                EntityManager em = (EntityManager) getValue("#{entityManager}");               
                em.persist(p);           
            }
           
          
         }.run();
        
View Full Code Here

                newComment.setContent("Testcomment Seven");
                newComment.setUseWikiText(true);

                newComment.setParent(d);

                em.persist(newComment);

                em.flush();
                em.clear();

                List<WikiComment> comments =
View Full Code Here

                newDir.setWikiname("FFF");
                newDir.setAreaNumber(d.getAreaNumber());
                newDir.setCreatedBy(em.find(User.class, 1l));
                newDir.setParent(d);

                em.persist(newDir);
                em.flush();

                em.clear();
                d = (WikiDirectory)
                        em.createQuery("select d from WikiDirectory d where d.id = :id")
View Full Code Here

                newDoc.setAreaNumber(d.getAreaNumber());
                newDoc.setCreatedBy(em.find(User.class, 1l));
                newDoc.setContent("Testdocument Four");
                newDoc.setParent(d);

                em.persist(newDoc);
                em.flush();

                em.clear();
                WikiDocument doc = (WikiDocument)
                        em.createQuery("select d from WikiDocument d where d.id = :id")
View Full Code Here

            @Override
            protected void invokeApplication() throws Exception {
                Thing thing = new Thing();
                thing.setName("thing");
                EntityManager entityManager = (EntityManager) getValue("#{entityManager}");
                entityManager.persist(thing);
                Contexts.getConversationContext().set("thing", thing);
                Manager.instance().beginConversation();
            }
        }.run();
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.