This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JPA PRO chapter 6 unsyncPC example modified

 
Ranch Hand
Posts: 1742
12
  • 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 Hand
Posts: 1742
12
  • 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:
CUSTOMERORDER Table:
ID  | Name
---------------------
1       pants_order

ORDERITEM table:
ID| Name |Quantity| item key | order id
----------------------------------------------
1      pants     100        pants           1
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!