CS636 Class 14

Finish Chap. 13 slides "More On JPA"

Note doc JPA2Notes.html with comments on the book pages, some overlap with notes on the slides.

Eclipse Debugging Demo

Look at pizza2, just posted.

But use pizza1 for debugging demo, since like current project.
Break it by changing insertOrder to insertOrderx in PizzaOrderDAO
Run with "ant hsqlSysTest", see exact reason and where.

Break it by putting "order = null;" just before call to insertOrder, in StudentService.makeOrder.
Run with "ant hsqlSysTest", see backtrace and NullPointerException reported from insertOrder in DAO, not the location of the mistake.
Run with debugger in eclipse: right-click SystemTest.java in project explorer, select Debug>Java application
See crash report, same as running with ant, except link to PizzaOrderDAO.java, site of crash (line of code)
Set breakpoint in PizzaOrderDAO: click along left-hand edge of editor window at desired line.
Run again with debugger: can use little bug icon at top of Debug window.
See before-crashed state in insertOrder, with back trace in window, editor on PizzaOrderDAO.java showing breakpoint
Click levels in back trace, see editor windows on various files.
Click makeOrder level, see its code, obvious problem user = null, but we'll pretend we don't see it yet.
Set breakpoint in caller, makeOrder, to find the cause.
Run again with debugger, stops in makeOrder, use step-over button to advance line by line, seeing variable values change.
Finally see user become null, that's the bug.

Can also step-into: rerun with breakpoint in SystemTest, step into makeOrder, etc.

Note debugger perspective, different from Java perspective, switch back and forth with perspective buttons.
You don't have to live with what is shown in the Debugger perspective:
Example: add Project Explorer view to Debugger display.


Note on DbDAO CRUD methods of pizza2

Still have CRD of CRUD, but don’t need Update methods in DAO.  Since the em tracks the managed domain objects, we can simply change their fields by calling their setters in the service layer. The em will be able to figure out that this field has been changed when it sends data to the database, usually at commit time.