Charting with Hibernate and AOP

I am trying to verify the action that the user performed, which led to changes in the respective tables. For example, if a user had to transfer money between two accounts, this would create the following sequence of events:

  • Enter the transfer amount in the transfer table
  • Subtract the transfer amount from the balance in the balance table for account 1.
  • Add the transfer amount to the balance in the balance table for account 2.

The parent audit message for all tables will be: "User-transported transfer of $ XXX"

This is achieved using the following scheme: scheme

alt text http://img48.imageshack.us/img48/7460/auditloggingiv6.png

The question is, how can I imagine this in sleep mode?

I created the following:

In balance and transfer mapping files

<set name="auditRecords" table="TransferAuditRecord" inverse="false" cascade="save-update">
  <key>
    <column name="AuditRecordID" not-null="true" />
  </key>
  <one-to-many class="audit.AuditRecord"/>
</set>

The carry and balance classes then implement IAuditable, which has methods

public void setAuditRecords(Set<AuditRecord> auditRecord);
public Set<AuditRecord> getAuditRecords();

In the AuditRecord mapping file, I have:

<many-to-one name="parentAuditRecord" lazy="false"
             column="parent_id"
             class="audit.AuditRecord"
             cascade="all" />

Then in the Logging class using AOP and Hibernate Interceptors I:

AuditRecord auditRecord = new AuditRecord();
auditRecord.setUser(userDAO.findById(
    org.springframework.security.context.SecurityContextHolder.getContext()
        .getAuthentication().getName()));

auditRecord.setParentAuditRecord(getCurrentActiveServiceRecord());

auditable.getAuditRecords().add(auditRecord);

Then in the service class, I call the following method, enclosed in a transaction:

save(balance1);
save(balance2);
transfer.setPassed(true);
update(transfer);

The parentAuditRecord element is created using an AOP with a stream safe stack, and the AuditRecordType_id is set using method annotations.

I left the passed column in the migration table. I used to call save (transfer) to insert the transfer amount into the Transfer table with the false value passed. (This action is also verified).

My requirements are a bit more complicated than the example above: P

So, the sequence of events for the above should be:

  • Refresh Transfer Table
  • Paste into AuditRecord (Parent)
  • AuditRecord ()
  • TransferAuditRecord
  • AuditRecord ()
  • BalanceAuditRecord
  • AuditRecord ()
  • BalanceAuditRecord

, , . Hibernate " " ( unsaved-value = "any" Mapping AuditRecord). "--", Transfer , . , . Hibernate " ", AuditRecord, AuditRecord TransferAuditRecord, TransientObjectException.

:

msg=... + ((AuditRecord) balance.getAuditRecords().toArray()[getAuditRecords().size()-1])
    .getParentAuditRecord().getAuditRecordType().getDescription() + ...;

: Msgstr " 12:00 11-Oct-2008"

EDIT "--" ( ), afterTransactionCompletion, ( ), . , . Envers, .

+3
2

, parentAuditRecord transferauditrecord . , , , , -.

http://www.hibernate.org/hib_docs/reference/en/html/inheritance.html

JBoss Envers.

+1

, db .

, (, , ), Hibernate-// ( : http://www.hibernate.org/hib_docs/v3/reference/en-US/html_single/)

, JBoss Envers, .

0

Source: https://habr.com/ru/post/1699427/


All Articles