[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5492?page=c...
]
Barry commented on HHH-5492:
----------------------------
I forgot to mention that the database driver I was using was ojdbc 10.1.0.5.0 (and same
with 10.2.0.5.0)
Anyway, I managed to get around this issue by using a PreInsertEventListener instead. In
the pre insert stage I register a transaction synchronization to do the actual work (I
still want it to happen post-insert). This seems to work.
{code}
public boolean onPreInsert(final PreInsertEvent event) {
if (!isAuditedEntity(event.getEntity())) {return false;}
TransactionSynchronizationManager.registerSynchronization(new
TransactionSynchronizationAdapter() {
@Override
public void beforeCommit(boolean readOnly) {
saveAuditRecords(event.getEntity(), event.getPersister(), new
Object[event.getState().length], event.getState(), event.getSession());
}
});
return false;
}
{code}
PostInsertListener doing new insert works on Mysql/HSQLDB, but not on
Oracle.
-----------------------------------------------------------------------------
Key: HHH-5492
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5492
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.4
Environment: Oracle Database 10g Express Edition Release 10.2.0.1.0 and Oracle
Database 11g Release 11.1.0.0.0
Reporter: Barry
Attachments: EventListener-test.zip
I'm trying to implement a hibernate event listener that inserts a new record every
time a specific entity is updated, deleted or inserted. I've implemented a listener
for post-insert, post-update, post-delete. Its a requirement that the new record is
inserted in the same transaction as the one that originally triggered the
update/deletion/insert.
The relevant section of my listener looks like this (similar for postInsert &
postDelete):
{code}
public void onPostUpdate(PostUpdateEvent event) {
if (isAuditable(event.getEntity())) {
saveAuditRecord(event.getSession());
}
}
private boolean isAuditable(Object entity) {
return entity instanceof SomeEntity;
}
private void saveAuditRecord(Session session) {
AuditRecord record = new AuditRecord();
record.setId(Double.doubleToLongBits(Math.random()));
session.save(record);
}
{code}
The listener is triggered for each event, but it seems as though the AuditRecord is not
saved when using an Oracle database. Using MySQL or HSQLDB works fine. So my guess is that
it has something to do with the Oracle dialect?
I've attached a test case which demonstrates it failing (but you will need to connect
to an Oracle DB :-)) Same result for Oracle XE and the full monty.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira