NullPointerException
Hi,
I am getting a NullPointerException that is difficult to resolve.
Background:
When a record is written for a class, Auditable, subsequent records are written for the audit record, ServiceAuditRecord and EntityAuditRecord. Every EntityAuditRecord record has a parent ServiceAuditRecord, and the parent ServiceAuditRecord may have many EntityAuditRecord children. The idea being to log a user's action that may require changes to many tables.
Relevant Classes:
Code:
AbstractAuditRecord (id, parent_log_id,...)
<Auditable>AuditRecord(<Auditable>_id,AbstractAuditRecord_id)
<Auditable> (id, ....)
(<Auditable> being the interface for the class to be audited)
Relevant Mapping Files:AbstractAuditRecord:
Code:
...
<set cascade="persist, delete-orphan" lazy="false"
name="childAuditRecords" sort="unsorted">
<key column="parent_log_id" />
<one-to-many
class="AbstractAuditRecord" />
</set>
<many-to-one name="parentAuditRecord"
lazy="false"
column="parent_log_id"
insert="false"
update="false"
class="AbstractAuditRecord"
cascade="persist,merge,save-update" />
...
<Auditable>:
Code:
...
<set name="entityAuditRecords" table="AvailableBalanceAuditRecord" lazy="true" cascade="save-update">
<key column="<Auditable>_ID" />
<many-to-many class="AbstractAuditRecord" column="AbstractAuditRecord_Id" unique="true" />
</set>
...
So a AbstractAuditRecord has many child records, and zero or one parent records.
A <Auditable> has one or more AbstractAuditRecords
In the Hibernate Interceptor we have the following code:
Code:
...
EntityAuditRecord auditRecord = createEntityAuditRecord(auditable);
getServiceRecord().getChildAuditRecords().add(auditRecord);
...
...
In createEntityAuditRecord:
...
auditable.getEntityAuditRecords().add(auditRecord);
...
This all works fine until later when we want to determine the action the user took:
In <Auditable>
Code:
...
private Set<AbstractAuditRecord> entityAuditRecords = new HashSet<EntityAuditRecord>();
...
msg = ((AbstractAuditRecord)(getEntityAuditRecords()).toArray()[0]).getServiceMessage();
...
Then in AbstractAuditRecord:
Code:
...
private AbstractAuditRecord parentAuditRecord;
...
In getServiceMessage():
getParentAuditRecord()....
...
getParentAuditRecord() throwing said NullPointerException