Skip to content

Conversation

marko-bekhta
Copy link
Member

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


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.


@marko-bekhta marko-bekhta requested a review from mbellade October 6, 2025 15:23
Comment on lines 55 to 60
ValidatorFactory factory, Map<String, Object> settings, ClassLoaderService classLoaderService) {
traversableResolver = new HibernateTraversableResolver();
validator =
ValidatorFactory factory, Map<String, Object> settings, ClassLoaderService classLoaderService,
SessionFactoryImplementor sessionFactory) {
this.traversableResolver = new HibernateTraversableResolver();
this.validator =
Copy link
Member

Choose a reason for hiding this comment

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

Technically, BeanValidationEventListener is an API, so we shouldn't change constructor signature.

Also, it looks like sessionFactoryCreated would be a better fit for this (even though that means having a non-final attribute), and we already use it to retrieve the metamodel there.

Copy link
Member Author

Choose a reason for hiding this comment

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

good point 👍🏻 🙂

Comment on lines +123 to +128
if ( session != null ) {
return session.getEntityPersister( entityName, entity );
}
return entityName == null
? sessionFactory.getMappingMetamodel().getEntityDescriptor( entity.getClass().getName() )
: sessionFactory.getMappingMetamodel().getEntityDescriptor( entityName )
.getSubclassEntityPersister( entity, sessionFactory );
}
Copy link
Member

Choose a reason for hiding this comment

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

This is a fine workaround, but I wonder if we could rather make org.hibernate.event.spi.AbstractSessionEvent take a org.hibernate.engine.spi.SharedSessionContractImplementor instead of org.hibernate.event.spi.EventSource, deprecating the old signature (and delegating to the new one since EventSource extends SharedSessionContractImplementor.

Since stateless session fire this events too now, it would make more sense to be able to retrieve them in AbstractSessionEvent#getSession (which, as the name implies, could not only return EventSources). Perhaps let's hear what @gavinking thinks.

Copy link
Member Author

Choose a reason for hiding this comment

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

+1 there is the

public abstract class AbstractEvent implements Serializable {
protected final SharedSessionContractImplementor source;

but it's a different hierarchy of events, and these collection ones don't get the same source 😖

@marko-bekhta marko-bekhta force-pushed the fix/HHH-19843-Bean-Validation-may-fail-on-operations-with-stateless-session branch from 2901ff0 to ebed130 Compare October 6, 2025 16:27
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