-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: NullPointerException
PostPosted: Sat Oct 25, 2008 12:30 pm 
Newbie

Joined: Tue Oct 21, 2008 4:13 pm
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.