Results 1 to 3 of 3

Thread: Property modified and hibernate persists (aspectJ)

  1. #1

    Default Property modified and hibernate persists (aspectJ)

    Hi community,

    though it's about AspectJ I hope you guys may help me.

    Scenario:

    We have an aspect that reacts as soon as in the packe com.xyz.entities a getter ist called that will return a String.
    The aspect itself now checks in a key value store if there are additional values and replaces the text out of the database with the one from the key value store.

    For instance, we have entity project with a description, which is being access now. my aspect now constructs out of the entity id, class name and field name that the aspect will look up. If the value of the fetched string is not equal null, replace the description out of the database with the one from the key-value store.

    Obviously, hibernate now thinks, the object is dirty and persists the value form the key value store to the database.

    How may I prevent this?

    All entities are always persists manually at each point, so could I prevent hibernate from flushing all data to the db?

    Thanks in advance,

    Hamb

  2. #2
    Join Date
    Nov 2007
    Posts
    420

    Default

    if you are persisting "manually" as you say, set flush mode to NEVER and manually flush the session yourself. if that is not viable solution you'll have to detach your objects from the session to prevent flush causing you these problems.

  3. #3

    Default

    Thanks for your reply. Just 5 minutes before you responded I found the solution you just gave me.

    We have a central AbstractDao.class from which each Dao has to extend. There is a method getFactory which returns the factory which in the counter-turn contains the current session.

    So just before we return the sessionFactory I do a

    Code:
    sessionFactory.getCurrentSession().setFlushMode(FlushMode.MANUAL);
    And it stops persisting. Great! Thank you!

    //The edit button says:

    Be careful though. If you rely on the flush mode "Auto" you may run into troubles that nothing ist persistet after you've applied my procedure :-)

    Hamb

Posting Permissions

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