Skip to content

Conversation

@inpink
Copy link

@inpink inpink commented Nov 6, 2025

[Please describe here what your change is about]

  • Added a dropTestData() attribute to @SessionFactory (default NEVER) so tests can opt into automatic cleanup declaratively.
  • Introduced the DropDataTiming enum to capture supported cleanup moments (NEVER, BEFORE/AFTER_EACH, BEFORE/AFTER_ALL).
  • Updated SessionFactoryExtension to store the configured timing and invoke scope.dropData() during the matching JUnit lifecycle callbacks (before/after each or all tests).
  • Added DropDataTimingTest to prove each timing option behaves as expected by inserting data and asserting whether it persists or gets cleared at the right moments.
  • Added SessionFactoryProducerDropDataTest to show that tests using only SessionFactoryProducer (no annotation) default to DropDataTiming.NEVER, keeping data until explicitly dropped.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19912

@inpink inpink marked this pull request as draft November 6, 2025 18:25
@inpink inpink force-pushed the inpink/HHH-19912 branch 2 times, most recently from ea9ba16 to 374fdb8 Compare November 6, 2025 18:31
Comment on lines 261 to 271
final Optional<SessionFactory> sfAnnRef = AnnotationSupport.findAnnotation(
context.getRequiredTestClass(),
SessionFactory.class
);

if (sfAnnRef.isPresent()) {
DropDataTiming configuredTiming = sfAnnRef.get().dropTestData();
if (configuredTiming == timing) {
scope.dropData();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, it would be better to keep track of this "drop timing" as the SessionFactory annotation is discovered on the class / method and kept in the JUnit ExtensionContext.Store.

See FailureExpectedExtension for an example of how we do this alsewhere.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the helpful guidance! I’ll finish the revisions soon and mention you again.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebersole I’ve finished preparing the PR. Could you please review it when you have a moment? Thanks a lot!

@inpink inpink force-pushed the inpink/HHH-19912 branch 3 times, most recently from 786f305 to ad5c292 Compare November 9, 2025 12:53
@inpink inpink marked this pull request as ready for review November 9, 2025 12:54
@inpink inpink requested a review from sebersole November 9, 2025 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants