Announcement Announcement Module
Collapse
No announcement yet.
OpenEntityManagerInViewFilter and Single Session Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • OpenEntityManagerInViewFilter and Single Session

    Can anyone advise why the OpenEntityManagerInViewFilter does not allow for a session per transaction (singleSession = false) as for the OpenSessionInViewFilter?

    As far as I can see there is also no mechanism to control the Flush Mode.

    I am trying to ascertain what the behaviour should be in the following case under the default configuration of OEMIV Filter:

    [1] Controller loads an existing entity in a transaction marked as readOnly and auto-binds user input.
    [2] Controller queries the database in a transaction marked as readOnly to determine if some fileld related to the entity is unique.

    The behaviour I am seeing in that before the query is executed in T2, Hibernate attempts to flush the state of the entity loaded in T1 and modified outside of a transaction. I can see why it might do that as both transactions are associated with the same session.

    Is this what should be happening however?

    I was under the impression that the readOnly flag would set the FlushMode to NEVER. However maybe I am misunderstanding and this will only be for the duration of this new transaction and not for entities modified in a previous transaction (in the same session).

    Under OpenSessionInViewFilter (as opposed to OEMIV Filter whcih I am using) I believe the default flush mode is NEVER. So wouldn't this also prevent the issue regardless of whether the transaction was marked as readOnly. I cannot find any documentation about FlushMode for OEMIV.

    Under OpenSessionInViewFilter (as opposed to OEMIV) there is an option to set singleSession to false. Again, I think this would fix the issue as T1 and T2 will no longer be associated with the same session

    Slightly confused by all this: I've only been using Spring and Hibernate for the last 6 years after all!


    Thanks.
    Last edited by alanhay; Apr 18th, 2013, 07:21 AM.

  • #2
    Well it turns out this could be fixed by specifying a JPAVendorAdapter (org.springframework.orm.jpa.vendor.HibernateJpaVe ndorAdapter) for the EntityManagerFactory configuration. While everything appears to work correctly without this (assuming a provider is specified in persistence.xml) obviously for whatever reason transactions do not work correctly in the scenario outlined above when the adapter is not specified.

    Interestingly, I copied the config for this project from a project I had previously bootstrapped with Roo. Now Roo does not configure a JpaVendorAdapter for the EntityManagerFactory but does configure the OpenEntityManagerInViewFilter which I guess may be something the Roo team might want to look at.

    The Roo bootstraped files did specify aspectj mode for the transaction manager while my project did not. Whether this would have any bearing on my subsequent issues I have no idea!

    Comment


    • #3
      Thank you for posting this and for the solution. I ran into this exact issue, specifying JPAVendorAdapter fixed it.

      Comment


      • #4
        Please, move your question to the StackOverflow - we are going to close this forum soon and rely on SO.
        We need to clean this forum (old unanswered question) before close it.

        Thanks for understanding

        Comment

        Working...
        X