Home

 

Displaying the SQL statements

We can configure the OpenJPA properties so that the SQL statements issued against the database are displayed.

Open the persistence.xml file (in RAD75JPATest).

Change the openjpa.Log property to the value SQL=TRACE:

<property name="openjpa.Log" value="SQL=TRACE" />

Rerun the test (Run Æ Run History Æ Entity Tester) and you can see the SQL statements:

All customers:

SELECT t0.ssn, t0.FIRST_NAME, t0.LAST_NAME, t0.title FROM ITSO.CUSTOMER t0

Customers by partial last name:

SELECT t0.ssn, t0.FIRST_NAME, t0.LAST_NAME, t0.title FROM ITSO.CUSTOMER t0 WHERE (t0.LAST_NAME LIKE ? ESCAPE '\') [params=(String) %a%]

Accounts of a customer:

SELECT t1.id, t1.balance FROM ITSO.ACCOUNT_CUSTOMER t0 INNER JOIN ITSO.ACCOUNT t1 ON t0.ACCOUNT_ID = t1.id WHERE t0.CUSTOMER_SSN = ? [params=(String) 333-33-3333]

Accounts of a customer sorted:

SELECT t0.id, t0.balance FROM ITSO.ACCOUNT t0 INNER JOIN ITSO.ACCOUNT_CUSTOMER t1 ON t0.id = t1.ACCOUNT_ID INNER JOIN ITSO.CUSTOMER t2 ON t1.CUSTOMER_SSN = t2.ssn WHERE (t1.CUSTOMER_SSN = ?) ORDER BY t0.id ASC [params=(String) 333-33-3333]

Perform a transaction:

INSERT INTO ITSO.TRANSACT (id, amount, TRANS_TIME, TRANS_TYPE, ACCOUNT_ID) VALUES (?, ?, ?, ?, ?) [params=(String) c77b2cb3-a4a6-4db3-bb27-22dec71b8bb2, (BigDecimal) 50, (Timestamp) 2008-08-11 16:12:49.406, (String) Debit, (String) 003-999000777]

Update the account balance after the transactions:

UPDATE ITSO.ACCOUNT SET balance = ? WHERE id = ? [params=(BigDecimal) 10026.52, (String) 003-999000777]

Transactions of an account:

SELECT t1.id, t1.ACCOUNT_ID, t1.amount, t1.TRANS_TIME, t1.TRANS_TYPE FROM ITSO.ACCOUNT t0 INNER JOIN ITSO.TRANSACT t1 ON t0.id = t1.ACCOUNT_ID WHERE (t0.id = ?) ORDER BY t1.TRANS_TIME ASC [params=(String) 003-999000777]

Replace value "SQL=TRACE" by the value "none" to deactivate the trace.
ibm.com/redbooks