This discussion is archived
0 Replies Latest reply: Dec 1, 2010 2:11 PM by 810430 RSS

Petstore 2 EA5 JPA issue -- think is bug, Win 7 64bit, JDK1.6.0_20, GFV301

810430 Newbie
Currently Being Moderated
JPA failure with gfv301 and the Petstore2EA5 sample from Sun Java Blueprints


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;

Because the local Entity item, type Item does not get updated with a PKey - from autogeneration,
later in the code where it tries to index the item it gets an exception due to the null field.

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,

From 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

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points