[JIRA] (HHH-16527) .CollectionBinder.bindManytoManyInverseFk does not handling exceptions.
by Zhong Hao (JIRA)
Zhong Hao ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYWI5MzNmZTgw... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16527?atlOrigin=eyJpIjoiYWI5Mz... ) HHH-16527 ( https://hibernate.atlassian.net/browse/HHH-16527?atlOrigin=eyJpIjoiYWI5Mz... ).CollectionBinder.bindManytoManyInverseFk does not handling exceptions. ( https://hibernate.atlassian.net/browse/HHH-16527?atlOrigin=eyJpIjoiYWI5Mz... )
Issue Type: Bug Affects Versions: 6.2.1 Assignee: Unassigned Components: hibernate-core Created: 26/Apr/2023 23:23 PM Environment:
Priority: Major Reporter: Zhong Hao ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
.CollectionBinder.bindManytoManyInverseFk has the following code:
public static void bindManytoManyInverseFk(PersistentClass referencedEntity,
Ejb3JoinColumn[] columns,
SimpleValue value,
boolean unique,
MetadataBuildingContext buildingContext) {
...
final Property property = referencedEntity.getRecursiveProperty( mappedBy );
..
}
The referencedEntity.getRecursiveProperty can throw MappingException. The other method of this class catches and rethrows AnnotationException:
protected boolean bindStarToManySecondPass(
Map<String, PersistentClass> persistentClasses,
XClass collType,
Ejb3JoinColumn[] fkJoinColumns,
Ejb3JoinColumn[] keyColumns,
Ejb3JoinColumn[] inverseColumns,
Ejb3Column[] elementColumns,
boolean isEmbedded,
XProperty property,
boolean unique,
TableBinder associationTableBinder,
boolean ignoreNotFound,
MetadataBuildingContext buildingContext) {
...
try {
reversePropertyInJoin = 0 != persistentClass.getJoinNumber(
persistentClass.getRecursiveProperty( this.mappedBy )
);
}
catch (MappingException e) {
throw new AnnotationException(
"mappedBy reference an unknown target entity property: " +
collType + "." + this.mappedBy +
" in " +
collection.getOwnerEntityName() +
"." +
property.getName()
);
}
...
}
As a result, the same type of errors can cause different types of exceptions. It would confuse programmers.
Catching AnnotationException can fail to handle the same errors in bindManytoManyInverseFk.
Can this problem be fixed?
( https://hibernate.atlassian.net/browse/HHH-16527#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16527#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100223- sha1:02266b8 )
1 year, 8 months
[JIRA] (HHH-16525) PersistentAttributesEnhancer.addCompositeOwnerInterface does not rethrow exceptions.
by Zhong Hao (JIRA)
Zhong Hao ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOGQ2OTE0MzEw... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16525?atlOrigin=eyJpIjoiOGQ2OT... ) HHH-16525 ( https://hibernate.atlassian.net/browse/HHH-16525?atlOrigin=eyJpIjoiOGQ2OT... ) PersistentAttributesEnhancer.addCompositeOwnerInterface does not rethrow exceptions. ( https://hibernate.atlassian.net/browse/HHH-16525?atlOrigin=eyJpIjoiOGQ2OT... )
Issue Type: Bug Assignee: Unassigned Components: hibernate-core Created: 26/Apr/2023 22:40 PM Priority: Major Reporter: Zhong Hao ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
PersistentAttributesEnhancer.java:addCompositeOwnerInterface has the following code:
private void addCompositeOwnerInterface(CtClass managedCtClass) throws NotFoundException, CannotCompileException {
...
if ( enhancementContext.isCompositeClass( managedCtClass ) ) {
// if a composite has an embedded field we need to implement the TRACKER_CHANGER_NAME method as well
MethodWriter.write(
managedCtClass,
"public void %1$s(String name) {%n" +
" if (%2$s != null) { %2$s.callOwner(\".\" + name); }%n}",
EnhancerConstants.TRACKER_CHANGER_NAME,
EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME
);
}
}
MethodWriter.write can throw CannotCompileException.
In this class, when MethodWriter.write , the other method rethrow EnhancementException:
protected CtMethod generateFieldReader(
...
try{
...
reader = MethodWriter.write(
managedCtClass, "public %s %s() {%n%s%n return %s;%n}",
persistentField.getType().getName(),
readerName,
typeDescriptor.buildReadInterceptionBodyFragment( fieldName ),
declared ? declaredReadFragment : superReadFragment
);
}catch (CannotCompileException cce) {
final String msg = String.format(
"Could not enhance entity class [%s] to add field reader method [%s]",
managedCtClass.getName(),
readerName
);
throw new EnhancementException( msg, cce );
}
catch (NotFoundException nfe) {
final String msg = String.format(
"Could not enhance entity class [%s] to add field reader method [%s]",
managedCtClass.getName(),
readerName
);
throw new EnhancementException( msg, nfe );
}
}
It is confusing. If calling code catches EnhancementException to handle errors, it will miss the errors occuring in addCompositeOwnerInterface.
Can this problem be fixed?
( https://hibernate.atlassian.net/browse/HHH-16525#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16525#add-comment?atlOrigin=ey... )
Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.... ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100223- sha1:02266b8 )
1 year, 8 months