Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

JPA PRO chapter 6 unsyncPC example modified

Ranch Foreman
Posts: 1897
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I added some notes to the unsynPC example:
1. include cdi-api.jar in the classpath. You can find it from your glassfish installation path/glassfish/modules.
Without it, it won't compile the ShoppingCart stateful bean with @SessionScope annotation.

2. In the sql statements provided, it is better to add auto increment for the keys of the two tables like this;

3. Add a web.xml like this:
Himai Minh
Ranch Foreman
Posts: 1897
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out that the original code of unsync in chapter 6 does not work when I restarted and redeploy the application.

For your reference , I made more modification to the example  to make it work:
1. I added a foreign key to the orderitem table:

The book uses 1, 2, 3.... for the id of customerID. That will cause duplicated primary key problem if you run this example for more than once.
That is why I decided to use automated generated ID.

In the shopping cart stateful bean, I modified into this:

Now, you will get something like this:
ID  | Name
1       pants_order

ID| Name |Quantity| item key | order id
1      pants     100        pants           1
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic