User's Manual

90 Chapter 9. Persistence Tutorial
Data Model Problem Likely Cause in PDL
Missing foreign keys Object Model doesn’t use associations, but data
model does, e.g. Message object has
BigDecimal authorID property instead of User
author property, in these cases an easy fix is to
create the author association without removing
the authorID attribute so that existing java code
continues to work.
Missing not null The property in PDL is [0..1] when it should be
[1..1].
Extra not null The property in PDL is [1..1] when it should be
[0..1].
Missing on delete cascade The property in PDL should be declare
component or composite.
Missing unique constraint The property(ies) in PDL should be declared
unique.
9.6.7. Debugging Persistence
When developing code using persistence, you may have a difficult time tracking down the
reason for a PersistenceException. Turning up the logging level can help you understand
what is going on. The following Log4J loggers com.redhat.persistence.Session and
com.redhat.persistence.engine.rdbms can be turned to the info log level to help see what is
going on. The latter will log all SQL being sent to the database.
9.7. Transaction Management
Within WAF, the Servlet Dispatchers handle all transactions for the developer. This document clarifies
the decisions that have been made regarding transactions within the WAF, and briefly discusses how
to manage transactions outside of the WAF.
9.7.1. Transactions within the WAF
The WAF imposes several restrictions on the developer that are important to understand:
Only one transaction may be open at a time for a given thread. More concretely, it is not possible
to nest transactions.
Writable Data Objects cannot be cached across transactions, because aborting a transaction requires
some way to either rollback or invalidate all DataObjects using the transaction. However, it is
possible to cache read-only data objects since they are loaded from the database a single time and
then never modified and they never again need to access the database. However, when doing this, it
is important that all read-only objects are removed from memory when a writable object is retrieved.
One feature to realize is that if a SQLException is thrown when using Postgres then the transaction is
aborted and it is no longer possible to interact with the database. Therefore, it is necessary to check
for all conditions that could cause an error to arise before actually making a call to the database.
When programming in the WAF, unless you are writing a dispatcher or initializer, you will most likely
not need to deal with transactions. However, if you do, the process is simple and is outlined in the next
section.