Results 1 to 2 of 2

Thread: Preventing flushing of EntityManager when @PreAuthorized methods on entities called

  1. #1
    Join Date
    Oct 2011
    Posts
    2

    Question Preventing flushing of EntityManager when @PreAuthorized methods on entities called

    Hi,

    I'm using @PreAuthorize annotations on my JPA-managed entities and I'm using AspectJ mode both in annotation driven transactions and in global-method-security. The problem is, in a @Transactional service method that calls multiple @PreAuthorized methods of an entity, statements are flushed every time before such a method. This means potentially DB constraints kicking in and also that our trigger-managed audit trail gets too many records. If I remove the security annotations, then there's only one statement flushed after the service method is completed.

    I wonder why is EntityManager flushed like that and is there a way to prevent it? I'm using EclipseLink and Spring's LocalContainerEntityManagerFactoryBean. Setting the order in tx:annotation-driven and global-method-security doesn't help in this case.

  2. #2
    Join Date
    Oct 2011
    Posts
    2

    Default

    I'll answer to myself: This was because of EclipseLink's default behavior of flushing statements when doing queries in a transaction (permission checks required DB queries). Setting "eclipselink.persistence-context.flush-mode" to "commit" in persistence.xml fixed the issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •