Using Hibernate 3.05, a class with <class ... mutable="false" ... > properly threw on any attempt to delete instances of that class from the database via Hibernate.
After upgrading to Hibernate 3.2.2, Hibernate allows deletion of class instances.
What am I (or, less likely, is Hibernate) doing wrong?
Thanks,
Tom
Code fragment:Code:
final AuditRecord record = new AuditRecord();
// setting of object properties elided
System.out.println("saving");
dao.save(record);
assertThat(record.getPrimaryKey(), NOT_NULL);
System.out.println("removing");
try {
dao.remove(record);
// In Hibernate 3.0.5, an exception is raised here.
// In Hibernate 3.2.2, the instance is deleted
fail("Should raise exception on attempt to delete an AuditRecord.");
}
catch (final Exception e) {
assertThat(e.getMessage(), NOT_NULL);
}
Code in dao.remove() method (extending Spring's HibernateDaoSupport):Code:
public void remove(final Object object) {
getHibernateTemplate().delete(object);
}
Hibernate version: 3.2.2
Mapping documents: (fragment)Code:
<class
name="com.foo.audit.model.AuditRecord"
table="audit_record"
mutable="false"
>
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
No exception occurs; this is the problem. ;)
Name and version of the database you are using:
MySQL 5.0
The generated SQL (show_sql=true):
[junit] saving
[junit] Hibernate: insert into audit_record (entity_class, entity_id, event_time, event_type, username, entity_version) values (?, ?, ?, ?, ?, ?)
[junit] Hibernate: insert into audit_record_state (audit_record_id, property_name, property_value) values (?, ?, ?)
[junit] Hibernate: insert into audit_record_state (audit_record_id, property_name, property_value) values (?, ?, ?)
[junit] removing
[junit] Hibernate: delete from audit_record_state where audit_record_id=?
[junit] Hibernate: delete from audit_record where id=?
[junit] Hibernate: select auditrecor0_.id as id5_0_, auditrecor0_.entity_class as entity2_5_0_, auditrecor0_.entity_id as entity3_5_0_, auditrecor0_.event_time as event4_5_0_, auditrecor0_.event_type as event5_5_0_, auditrecor0_.username as username5_0_, auditrecor0_.entity_version as entity7_5_0_ from audit_record auditrecor0_ where auditrecor0_.id=?
[junit] Hibernate: select state0_.audit_record_id as audit1_0_, state0_.property_value as property2_0_, state0_.property_name as property3_0_ from audit_record_state state0_ where state0_.audit_record_id=?