Details

    • Type: Technical task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.3.0.Beta5, 4.2.7
    • Component/s: None
    • Labels:
      None
    • Last commented by a user?:
      true

      Description

      http://in.relation.to/Bloggers/OptionsForEntityDirtnessChecking is a great discussion of the current state.

      The basic idea with this feature is to allow the entity to dirty-check itself through bytecode enhancement as discussed in the Tracked approach : bytecode enhancement section. So in part the code will simply be moved over from org.hibernate.bytecode.internal.javassist.JavassistClassTransformer to org.hibernate.bytecode.enhance.spi.Enhancer.

      But also, the other part is to allow different ways to request the checking be done. Some options we discussed were:

      • instance checking (with ==) - by far the most performant option, but not feasible in cases where the state of the thing being checked can mutate internally
      • Hibernate Type checking - The Hibernate org.hibernate.type.Type for the changing attribute would be used to perform the equality check

      A related consideration is having the entity track its loaded state. This would allow for more efficient (select-before-update not needed) reattachment of enhanced entities.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              stalep Ståle W. Pedersen added a comment -

              Ive changed the name of the interface to SelfDirtinessTracker, it also have a clear method.
              regarding the composite problem, i havent thought this through heavily so bear with me
              is it possible to find out at this stage (in Enhancher) if a field is another entity object? if so during isDirty we could call their isDirty method instead of calling equals. if the class is annotated i think this should be easy, i guess not so easy if its mapped with xml?

              ive looked at the DefaultFlushEntityEventListener#dirtyCheck, so i think this check should only be used if the custom hasnt found anything?
              mapping the field names to the int[] should be possible i think as long as i can find how the int[] is generated originally

              btw, should i check if the entity has already been enhanced and should perhaps the dirtychecker ignore primary key fields?

              Show
              stalep Ståle W. Pedersen added a comment - Ive changed the name of the interface to SelfDirtinessTracker, it also have a clear method. regarding the composite problem, i havent thought this through heavily so bear with me is it possible to find out at this stage (in Enhancher) if a field is another entity object? if so during isDirty we could call their isDirty method instead of calling equals. if the class is annotated i think this should be easy, i guess not so easy if its mapped with xml? ive looked at the DefaultFlushEntityEventListener#dirtyCheck, so i think this check should only be used if the custom hasnt found anything? mapping the field names to the int[] should be possible i think as long as i can find how the int[] is generated originally btw, should i check if the entity has already been enhanced and should perhaps the dirtychecker ignore primary key fields?
              Hide
              stalep Ståle W. Pedersen added a comment - - edited

              ive added a bit better dirtychecking i believe, so it should catch person.getAddress().setCity( "austin"). i still need to add checks for fields that inherits Collection.
              the methods ive added looks like this for the SimpleEntity class we're testing with:

                private boolean $$hibernate_isEntityDirty(Object paramObject)
                {
                  return (!(paramObject instanceof SelfDirtinessTracker)) || (((SelfDirtinessTracker)paramObject).$$hibernate_hasDirtyAttributes());
                }
                
                private boolean $$hibernate_areEntityFieldsDirty()
                {
                  return $$hibernate_isEntityDirty($$_hibernate_read_address());
                }
                
                public boolean $$hibernate_hasDirtyAttributes()
                {
                  return ((this.$$_hibernate_tracker == null) || (this.$$_hibernate_tracker.isEmpty())) && ($$hibernate_areEntityFieldsDirty());
                }
              
              Show
              stalep Ståle W. Pedersen added a comment - - edited ive added a bit better dirtychecking i believe, so it should catch person.getAddress().setCity( "austin") . i still need to add checks for fields that inherits Collection. the methods ive added looks like this for the SimpleEntity class we're testing with: private boolean $$hibernate_isEntityDirty( Object paramObject) { return (!(paramObject instanceof SelfDirtinessTracker)) || (((SelfDirtinessTracker)paramObject).$$hibernate_hasDirtyAttributes()); } private boolean $$hibernate_areEntityFieldsDirty() { return $$hibernate_isEntityDirty($$_hibernate_read_address()); } public boolean $$hibernate_hasDirtyAttributes() { return (( this .$$_hibernate_tracker == null ) || ( this .$$_hibernate_tracker.isEmpty())) && ($$hibernate_areEntityFieldsDirty()); }
              Hide
              stalep Ståle W. Pedersen added a comment - - edited
              Show
              stalep Ståle W. Pedersen added a comment - - edited ive merged all the commits into one big commit here: https://github.com/stalep/hibernate-orm/commit/5b6f086bdc9d973b309a2ad97eb4591b4229bb4c
              Hide
              steve Steve Ebersole added a comment -

              Linked pull request

              Show
              steve Steve Ebersole added a comment - Linked pull request
              Hide
              brmeyer Brett Meyer added a comment -

              Ståle W. Pedersen, this is going into EAP 6.2.0 ER7. Did you have any BZs open that I should attach to our upgrade ticket?

              Show
              brmeyer Brett Meyer added a comment - Ståle W. Pedersen , this is going into EAP 6.2.0 ER7. Did you have any BZs open that I should attach to our upgrade ticket?

                People

                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:

                    Development