-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-19843 Get persister from session factory if session is not available #11067
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
base: main
Are you sure you want to change the base?
Conversation
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 = |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point 👍🏻 🙂
if ( session != null ) { | ||
return session.getEntityPersister( entityName, entity ); | ||
} | ||
return entityName == null | ||
? sessionFactory.getMappingMetamodel().getEntityDescriptor( entity.getClass().getName() ) | ||
: sessionFactory.getMappingMetamodel().getEntityDescriptor( entityName ) | ||
.getSubclassEntityPersister( entity, sessionFactory ); | ||
} |
There was a problem hiding this comment.
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 EventSource
s). Perhaps let's hear what @gavinking thinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 there is the
hibernate-orm/hibernate-core/src/main/java/org/hibernate/event/spi/AbstractEvent.java
Lines 18 to 19 in 1753cb6
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 😖
2901ff0
to
ebed130
Compare
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.