The project uses Hibernate 3.5, Spring Webflow 2, and Hibernate Envers for auditing. Envers is configured in the hibernate.cfg.xml file. I have a one-to-many relationship mapping between an ArticleGroup and Article entity. In the "articles" of the table there is a foreign key "article_group_id" link to the identifier in the table "article_groups". In the interface, when I delete an article, Hibernate Envers throws a constraint exception for the post-delete event. If I do not use Envers, remote operations work fine. These two objects are defined as follows:
@Entity @Table(name="article_groups") @Audited public class ArticleGroup implements Serializable { @OneToMany(mappedBy="articleGroup", fetch = FetchType.EAGER, cascade = CascadeType.ALL) @OrderBy("id") private List<Article> articles; // other fields, getters and setters } @Entity @Table(name="articles") @Audited public class Article implements Serializable { @ManyToOne @JoinColumn(name = "article_group_id") private ArticleGroup articleGroup; // other fields, getters, setters }
Deleting an article is encoded as follows:
@Service("articleManager") public class ArticleManagerImpl implements ArticleManager {
Exclusion of violation of restrictions:
Hibernate: delete from live.articles where id=? Hibernate: select nextval ('hibernate_sequence') Hibernate: insert into audit.REVINFO (REVTSTMP, REV) values (?, ?) Hibernate: insert into audit.articles_AUD (REVTYPE, content, language, name, order_number, title, article_group_id, id, REV) values (?, ?, ?, ?, ?, ?, ?, ?, ?) 82828 [http-bio-8080-exec-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction rollback after commit exception org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update ... Caused by: java.sql.BatchUpdateException: Batch entry 0 insert into audit.articles_AUD (REVTYPE, content, language, name, order_number, title, article_group_id, id, REV) values ('2', NULL, NULL, NULL, NULL, NULL, NULL, '14', '17') was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2619)
As you can see, when Envers inserts 'audit.articles_AUD' into the table, article_group_id is null, which caused a constraint violation. Does anyone know how to fix this? Thank you very much.