| There are two methods that play an important role in determining the described behaviors.
- org.hibernate.jpamodelgen.util.TypeUtils.determineAccessTypeForHierarchy(TypeElement, Context)
- org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity.addPersistentMembers(List<? extends Element>, AccessType)
- domain 1
First, we look at org.hibernate.jpamodelgen.util.TypeUtils.determineAccessTypeForHierarchy(TypeElement, Context) to determine the access type for the entity domain1.Book. There is no explicit access type on domain1.Book. Since the entity is the root of the class hierarchy and defines an id. Its default access type is set to FIELD. Now, we look at org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity.addPersistentMembers(List<? extends Element>, AccessType) for both the Author field and getAuthor() method in domain1.Book.
- Author field
-> the entity access type is the same as the member's kind (FIELD) -> the annotations on the field are processed -> the ManyToOne annotation is present -> the Author attirubte is a basic attribute (org.hibernate.jpamodelgen.annotation.MetaAttributeGenerationVisitor.isBasicAttribute(Element, Element)) -> the Author attribute is returned and added to domain1.Book
- getAuthor() method
-> the entity access type (FIELD) is not the same as the member's kind (PROPERTY) and there's no forced access type on the member -> the getAuthor() method is not processed
- domain 2
First, we look at org.hibernate.jpamodelgen.util.TypeUtils.determineAccessTypeForHierarchy(TypeElement, Context) to determine the access type for the entity domain2.Book. There is no explicit access type on domain2.Book. Since the entity neither has a superclass nor defines an id, its default access type is set to PROPERTY. Now, we look at org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity.addPersistentMembers(List<? extends Element>, AccessType) for both the Author field and getAuthor() method in domain2.Book.
- Author field
-> the entity access type (PROPERTY) is not the same as the member's kind (FIELD) and there's no forced access type on the member -> the Author field is not processed
- getAuthor() method
-> the entity access type (PROPERTY) is the same as the member's kind (PROPERTY) -> the annotations on the method is processed -> there is no annotation on this method -> the getAuthor() method is not a basic attribute -> null is returned thus not added to domain2.Book
- domain 3
First, we look at org.hibernate.jpamodelgen.util.TypeUtils.determineAccessTypeForHierarchy(TypeElement, Context) to determine the access type for the entity domain3.Book. There is no explicit access type on domain3.Book. Since the entity neither has a superclass nor defines an id, its default access type is set to PROPERTY. Now, we look at org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity.addPersistentMembers(List<? extends Element>, AccessType) for both the Author field and getAuthor() method in domain3.Book.
- Author field
-> the entity access type (PROPERTY) is not the same as the member's kind (FIELD) and there's no forced access type on the member -> the Author field is not processed
- getAuthor() method
-> the entity access type (PROPERTY) is the same as the member's kind (PROPERTY) -> the annotations on the method is processed -> there is no annotation on this method -> however, domain3.Author implements java.io.Serializable which makes the return value of getAuthor() method a basic attribute (org.hibernate.jpamodelgen.annotation.BasicAttributeVisitor.visitDeclared(DeclaredType, Element)) -> the Author attribute is returned and added to domain2.Book
- domain 4
Since the Author field in domain4.Book is annotated with an access type, the Author field has a forced access type. As long as the field has a forced access type, the field is processed. Now, we look at org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity.addPersistentMembers(List<? extends Element>, AccessType) for both the Author field and getAuthor() method in domain1.Book.
- Author field
-> the field has a forced access type -> the annotations on the field are processed -> the ManyToOne annotation is present -> the Author attribute is a basic attribute (org.hibernate.jpamodelgen.annotation.MetaAttributeGenerationVisitor.isBasicAttribute(Element, Element)) -> the Author attribute is returned and added to domain4.Book
- getAuthor() method
-> the entity access type (PROPERTY) is the same as the member's kind (PROPERTY) -> the annotations on the method is processed -> there is no annotation on this method -> the getAuthor() method is not a basic attribute -> null is returned thus not added to domain4.Book
|