Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Envers - Proposal fix for HHH-4646 and HHH-5177 #3

Merged
4 commits merged into from
Oct 21, 2010
Merged

Envers - Proposal fix for HHH-4646 and HHH-5177 #3

4 commits merged into from
Oct 21, 2010

Conversation

hchanfreau
Copy link
Contributor

Hi!

It's my first pull request. I hope to be doing well.
As I mencioned on envers forum I've been working on this issuues.

Regards. Hernán.

Deleting obsolete tests
added methods isEmpty() and contains(key)
- Read audited properties from subclasses first, then check recursively on superclasses.
- Chech on superclasses only if a class is audited
- Calculate if the "current" class of the recursion is audited at class level.
- Created ComponentAuditedPropertiesReader subclass for AuditedPropertiesReader to use for reading component audited properties inside classes
- Created a protected method in AuditedPropertiesReader, letting the subclass do their job.
- Ordered the code to be more understandable.
Adding tests cases:
- MappedSuperclass audited at class level with a NotAuditedSubclass and:
	- Audited subclass at class level
	- Audited subclass at method/field level
- MappedSuperclass audited at method/field level with a NotAuditedSubclass and:
	- Audited subclass at class level
	- Audited subclass at method/field level
@adamw
Copy link
Member

adamw commented Oct 21, 2010

I looked at the patch and I've got one question: why do the the methods addPropertiesFromClass and addPropertiesFromClassRec differ? Shouldn't properties be always read first, and then superclasses?

@hchanfreau
Copy link
Contributor Author

Oh yes! You're right. The method addPropertiesFromClassRec must be:

private void addPropertiesFromClassRec(XClass clazz)  {

    Audited allClassAudited = clazz.getAnnotation(Audited.class);

    addFromProperties(clazz.getDeclaredProperties("field"), "field", fieldAccessedPersistentProperties, allClassAudited);
    addFromProperties(clazz.getDeclaredProperties("property"), "property", propertyAccessedPersistentProperties, allClassAudited);

    XClass superclazz = clazz.getSuperclass();
    if (!clazz.isInterface() && !"java.lang.Object".equals(superclazz.getName())) {
        addPropertiesFromClassRec(superclazz);
    }

}

@adamw
Copy link
Member

adamw commented Oct 21, 2010

So then the addPropertiesFromClassRec method can be removed compeltely. Trying :)

@hchanfreau
Copy link
Contributor Author

Yes! sorry for that mistake.

@adamw
Copy link
Member

adamw commented Oct 21, 2010

Pushed into 3.6

@adamw
Copy link
Member

adamw commented Oct 22, 2010

Merging these changes to the master branch isn't that easy. If you've got an idea on how to do it, let me know :)

@hchanfreau
Copy link
Contributor Author

What's the problem? Is there a refactor or something on sources on master?
I'll try to send another pull req for master if I can figure it out.

@adamw
Copy link
Member

adamw commented Oct 23, 2010

Yes, the modules are renamed from envers to hibernate-envers. In fact I'm looking for a generic solution on how to merge some commits from 3.6 to master. So if you find a way, please share :)

@hchanfreau
Copy link
Contributor Author

Oh! I see... All modules were renamed, so it's an issue for all components.
The way master -> 3.6 would be easy or it's the same?

@adamw
Copy link
Member

adamw commented Oct 25, 2010

I think it would be the same - the problem is that git doesn't recognize the rename. I'm planning on creating a create patch - rename paths with sed - apply patch script which takes git commit hashes, but didn't have time yet ;)

yrodiere added a commit to yrodiere/hibernate-orm that referenced this pull request Apr 7, 2020
…lizedAssociationTest

This test accesses a field of an entity directly and expects it to be
automatically initialized; this cannot work without extended bytecode
enhancement.

This used to work with Java 8 bytecode, but only by chance. It seems
that Java 8 bytecode relies on "synthetic", static access methods
inserted by the compiler to access the fields of entities in this test:
any access to the field is done through this access method instead of
through a direct field access. Since we apply bytecode enhancement to
all methods of entities, this means that access to fields triggers
initialization, without any bytecode enhancement in the caller class.

I believe this is specific to nested classes, but couldn't find a
source. For reference, the bytecode of access methods looks like this:

  static int access$002(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, int);
    Code:
       0: aload_0
       1: iload_1
       2: dup_x1
       3: putfield      hibernate#3                  // Field id:I
       6: ireturn

  static org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId access$102(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId);
    Code:
       0: aload_0
       1: aload_1
       2: dup_x1
       3: putfield      hibernate#2                  // Field entityImmutableNaturalId:Lorg/hibernate/test/bytecode/enhancement/lazy/NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId;
       6: areturn

With Java 11, however, access to fields of entities is done directly,
even for nested classes. So the access methods no longer exist, and we
don't get automatic initialization upon field access. We need extended
bytecode enhancement, like we would in any other case of field access
(in particular accessing fields of non-nested classes).
Sanne pushed a commit that referenced this pull request Apr 14, 2020
…lizedAssociationTest

This test accesses a field of an entity directly and expects it to be
automatically initialized; this cannot work without extended bytecode
enhancement.

This used to work with Java 8 bytecode, but only by chance. It seems
that Java 8 bytecode relies on "synthetic", static access methods
inserted by the compiler to access the fields of entities in this test:
any access to the field is done through this access method instead of
through a direct field access. Since we apply bytecode enhancement to
all methods of entities, this means that access to fields triggers
initialization, without any bytecode enhancement in the caller class.

I believe this is specific to nested classes, but couldn't find a
source. For reference, the bytecode of access methods looks like this:

  static int access$002(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, int);
    Code:
       0: aload_0
       1: iload_1
       2: dup_x1
       3: putfield      #3                  // Field id:I
       6: ireturn

  static org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId access$102(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId);
    Code:
       0: aload_0
       1: aload_1
       2: dup_x1
       3: putfield      #2                  // Field entityImmutableNaturalId:Lorg/hibernate/test/bytecode/enhancement/lazy/NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId;
       6: areturn

With Java 11, however, access to fields of entities is done directly,
even for nested classes. So the access methods no longer exist, and we
don't get automatic initialization upon field access. We need extended
bytecode enhancement, like we would in any other case of field access
(in particular accessing fields of non-nested classes).
yrodiere added a commit to yrodiere/hibernate-orm that referenced this pull request Nov 12, 2020
…lizedAssociationTest

This test accesses a field of an entity directly and expects it to be
automatically initialized; this cannot work without extended bytecode
enhancement.

This used to work with Java 8 bytecode, but only by chance. It seems
that Java 8 bytecode relies on "synthetic", static access methods
inserted by the compiler to access the fields of entities in this test:
any access to the field is done through this access method instead of
through a direct field access. Since we apply bytecode enhancement to
all methods of entities, this means that access to fields triggers
initialization, without any bytecode enhancement in the caller class.

I believe this is specific to nested classes, but couldn't find a
source. For reference, the bytecode of access methods looks like this:

  static int access$002(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, int);
    Code:
       0: aload_0
       1: iload_1
       2: dup_x1
       3: putfield      hibernate#3                  // Field id:I
       6: ireturn

  static org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId access$102(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId);
    Code:
       0: aload_0
       1: aload_1
       2: dup_x1
       3: putfield      hibernate#2                  // Field entityImmutableNaturalId:Lorg/hibernate/test/bytecode/enhancement/lazy/NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId;
       6: areturn

With Java 11, however, access to fields of entities is done directly,
even for nested classes. So the access methods no longer exist, and we
don't get automatic initialization upon field access. We need extended
bytecode enhancement, like we would in any other case of field access
(in particular accessing fields of non-nested classes).
yrodiere added a commit to yrodiere/hibernate-orm that referenced this pull request Jan 7, 2021
…lizedAssociationTest

This test accesses a field of an entity directly and expects it to be
automatically initialized; this cannot work without extended bytecode
enhancement.

This used to work with Java 8 bytecode, but only by chance. It seems
that Java 8 bytecode relies on "synthetic", static access methods
inserted by the compiler to access the fields of entities in this test:
any access to the field is done through this access method instead of
through a direct field access. Since we apply bytecode enhancement to
all methods of entities, this means that access to fields triggers
initialization, without any bytecode enhancement in the caller class.

I believe this is specific to nested classes, but couldn't find a
source. For reference, the bytecode of access methods looks like this:

  static int access$002(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, int);
    Code:
       0: aload_0
       1: iload_1
       2: dup_x1
       3: putfield      hibernate#3                  // Field id:I
       6: ireturn

  static org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId access$102(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId);
    Code:
       0: aload_0
       1: aload_1
       2: dup_x1
       3: putfield      hibernate#2                  // Field entityImmutableNaturalId:Lorg/hibernate/test/bytecode/enhancement/lazy/NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId;
       6: areturn

With Java 11, however, access to fields of entities is done directly,
even for nested classes. So the access methods no longer exist, and we
don't get automatic initialization upon field access. We need extended
bytecode enhancement, like we would in any other case of field access
(in particular accessing fields of non-nested classes).
gbadner pushed a commit that referenced this pull request Jun 4, 2021
…lizedAssociationTest

This test accesses a field of an entity directly and expects it to be
automatically initialized; this cannot work without extended bytecode
enhancement.

This used to work with Java 8 bytecode, but only by chance. It seems
that Java 8 bytecode relies on "synthetic", static access methods
inserted by the compiler to access the fields of entities in this test:
any access to the field is done through this access method instead of
through a direct field access. Since we apply bytecode enhancement to
all methods of entities, this means that access to fields triggers
initialization, without any bytecode enhancement in the caller class.

I believe this is specific to nested classes, but couldn't find a
source. For reference, the bytecode of access methods looks like this:

  static int access$002(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, int);
    Code:
       0: aload_0
       1: iload_1
       2: dup_x1
       3: putfield      #3                  // Field id:I
       6: ireturn

  static org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId access$102(org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$AnEntity, org.hibernate.test.bytecode.enhancement.lazy.NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId);
    Code:
       0: aload_0
       1: aload_1
       2: dup_x1
       3: putfield      #2                  // Field entityImmutableNaturalId:Lorg/hibernate/test/bytecode/enhancement/lazy/NaturalIdInUninitializedAssociationTest$EntityImmutableNaturalId;
       6: areturn

With Java 11, however, access to fields of entities is done directly,
even for nested classes. So the access methods no longer exist, and we
don't get automatic initialization upon field access. We need extended
bytecode enhancement, like we would in any other case of field access
(in particular accessing fields of non-nested classes).

(cherry picked from commit 1060baf)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants