-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add internal docs and do other improvements #80
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,22 @@ | |
|
||
import com.mongodb.hibernate.internal.FeatureNotSupportedException; | ||
import org.hibernate.annotations.DynamicInsert; | ||
import org.hibernate.boot.Metadata; | ||
import org.hibernate.boot.MetadataSources; | ||
import org.hibernate.boot.ResourceStreamLocator; | ||
import org.hibernate.boot.registry.BootstrapServiceRegistry; | ||
import org.hibernate.boot.spi.AdditionalMappingContributions; | ||
import org.hibernate.boot.spi.AdditionalMappingContributor; | ||
import org.hibernate.boot.spi.InFlightMetadataCollector; | ||
import org.hibernate.boot.spi.MetadataBuildingContext; | ||
import org.hibernate.mapping.PersistentClass; | ||
|
||
/** | ||
* The instance methods like {@link #getContributorName()}, {@link #contribute(AdditionalMappingContributions, | ||
* InFlightMetadataCollector, ResourceStreamLocator, MetadataBuildingContext)} are called multiple times if multiple | ||
* {@link Metadata} instances are {@linkplain MetadataSources#buildMetadata() built} using the same | ||
* {@link BootstrapServiceRegistry}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Javadoc is visible to public even though it is within internal package, right? To my best knowledge, I don't expect any Hibernate I'd thought you plan to put down such doc outside our code. Putting it here seems to hurt our product for they might clarify some doubts to us but would confuse others (including me). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, our whole codebase is publicly visible.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need to build multiple Metadata? Yeah, Hibernate doesn't disallow, but I dont' understand why we need to consider this case. From my best knowledge, such contributor only needs to be called once. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Given our codebase is public, there is still possibility that the doc could be read by others (e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let me elaborate on why I got confused. Hibernate's contributor is to be created by default constructor (via JDK's ServiceLoader mechanism or Such contributor hooking point is hard-coded in Hibernate code as below:
As you can see, for each contributor, its two methods will be called only once after it is loaded or created. So it seems a typical one-use scenario as our various mql translators. |
||
*/ | ||
public final class MongoAdditionalMappingContributor implements AdditionalMappingContributor { | ||
|
||
public MongoAdditionalMappingContributor() {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,9 @@ | |
import java.io.Serial; | ||
import java.util.Map; | ||
import org.hibernate.HibernateException; | ||
import org.hibernate.boot.registry.BootstrapServiceRegistry; | ||
import org.hibernate.boot.registry.StandardServiceInitiator; | ||
import org.hibernate.boot.registry.StandardServiceRegistry; | ||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; | ||
import org.hibernate.service.Service; | ||
import org.hibernate.service.UnknownServiceException; | ||
|
@@ -49,6 +51,11 @@ public MongoConfiguration getConfiguration() { | |
return config; | ||
} | ||
|
||
/** | ||
* The instance methods like {@link #contribute(StandardServiceRegistryBuilder)} are called multiple times if | ||
* multiple {@link StandardServiceRegistry} instances are {@linkplain StandardServiceRegistryBuilder#build() built} | ||
* using the same {@link BootstrapServiceRegistry}. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, I failed to see why multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that matters. What does matter is that doing so is possible with the API of Hibernate ORM, and it is not forbidden by the API documentation, so we must take that into account when we are extending Hibernate ORM. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is why I got confused. Yeah, it is not forbidden, but why we need to cover it? I never know of such scenario that we need to create multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So from my understanding, Hibernate's If multiple During runtime, one
From my understanding, one and only one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above comment also explains why I got puzzled by your previous PR; but you modified it to make it aligned with reality so I approved that. |
||
public static final class ServiceContributor implements org.hibernate.service.spi.ServiceContributor { | ||
public ServiceContributor() {} | ||
|
||
|
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 way we work around the issue fixed in hibernate/hibernate-orm#9900, because we are not getting that fix in Hibernate ORM 6.x.
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.
Thanks for your raising the issue and it is a quick fix. On the other hand, it seems trivial to me for we only avoid one unnecessary duplicated object creation (which usually is not a big deal for the creation is not costly).
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.
The other id generator defect is more important and hard to fix from Hibernate side. I created a PR at hibernate/hibernate-orm#9965. Let us see.