users@glassfish.java.net

JPA failure with gfv301 and the Petstore2EA5 sample from Sun Java Blueprints

From: emiddio-frontier <emiddio_at_frontier.com>
Date: Tue, 30 Nov 2010 13:16:41 -0800

the following code fragment when invoked in the application does not get
any JPA exceptions,
but always reports em.contains(item) as false;

when i use the same Entity classes in a standalone POJO app using JPA,
with RESOUCE LOCAL,
anytime an Item instance is persisted by em.persist(item)
i always get back from em.contains(item) the value true;

the item does get put into the derby database; but the PKey field stays null
in the local copy;



I am new to JPA -- so trying to understand what the problem is and where;

this code is from the Sun's Java Blueprints Petstore 2 EA5 Sample,
int CatalogFacade.java, method AddItem(Item item).

code fragment -----

             utx.begin();
             em.joinTransaction();

             for (Tag tag : item.getTags()) {
                 tag.incrementRefCount();
                 tag.getItems().add(item);
                 em.merge(tag);
             }

             System.out.println("contains ni : " + em.contains(item));
--get false
             System.out.println(item.getItemID()); --get null --
autogenerated PK
             em.persist(item);
             System.out.println("contains ni : " + em.contains(item));
-- get false
             System.out.println(item.getItemID()); -- get null
             em.flush();
             System.out.println("contains ni : " + em.contains(item));
-- get false
             System.out.println(item.getItemID()); -- get null
             utx.commit();
             System.out.println("contains ni : " + em.contains(item));
-- get false