Skip to content

Conversation

stIncMale
Copy link
Member


public static final ObjectIdJdbcType INSTANCE = new ObjectIdJdbcType();
public static final MqlType MQL_TYPE = MqlType.OBJECT_ID;
public static final SQLType MQL_TYPE = MqlType.OBJECT_ID;
Copy link
Member Author

Choose a reason for hiding this comment

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

I made MqlType package-access, as it does not need to be public.

Copy link
Member Author

Choose a reason for hiding this comment

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

TODO @stIncMale Rename the field to SQL_TYPE.

typeContributions.contributeJavaType(ObjectIdJavaType.INSTANCE);
typeContributions.contributeJdbcType(ObjectIdJdbcType.INSTANCE);
var objectIdTypeCode = MqlType.OBJECT_ID.getVendorTypeNumber();
var objectIdTypeCode = ObjectIdJdbcType.MQL_TYPE.getVendorTypeNumber();
Copy link
Member Author

Choose a reason for hiding this comment

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

MqlType was made package-access. Furthermore, ObjectIdJdbcType.MQL_TYPE explicitly points to our implementation of the JdbcType for ObjectId, which improves readability.

throw exceptionDomainTypeUnsupportedOrMustBeExplicit(value, domainType);
}

public static @Nullable Object toDomainValue(BsonValue value) throws SQLFeatureNotSupportedException {
Copy link
Member Author

Choose a reason for hiding this comment

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

This PR only needed this new method. However, I also wanted to stop using Object.class to represent "unknown domain type", which caused the rest of the changes.

@Table(name = COLLECTION_NAME)
@SqlResultSetMapping(
name = ItemWithFlattenedValue.MAPPING_FOR_FLATTENED_VALUE,
columns = {
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried also using SqlResultSetMapping.classes, but I don't think Hibernate ORM implements that one correctly: instead of trying to find the corresponding constructor, it uses the no-argument constructor and then tries to populate the object, searching for the field/property based on the ColumnResult.name, which represents the column name, and does not have to match the name of a field/property.

@stIncMale stIncMale force-pushed the HIBERNATE-60 branch 2 times, most recently from 02c39c7 to 51b953e Compare September 21, 2025 03:01
@stIncMale stIncMale marked this pull request as ready for review September 29, 2025 21:26
@stIncMale stIncMale requested a review from a team as a code owner September 29, 2025 21:26
@Table(name = COLLECTION_NAME)
static class ItemWithArrayAndCollectionValues {
@SqlResultSetMapping(
name = ItemWithArrayAndCollectionValues.MAPPING_FOR_ITEM,
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO @stIncMale File a ticket about creating a static helper method project(ItemWithArrayAndCollectionValues.class, ItemWithArrayAndCollectionValues.MAPPING_FOR_ITEM) that constructs the $project stage.

* queries</a>, {@link QueryProducer#createNativeQuery(String, Class)}.
*/
@Test
void testScalar() {
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO @stIncMale

Add

() -> {
    var mql = mql(COLLECTION_NAME, List.of(match(eq(itemWithNestedValue.id)), project(include("nested"))));
    assertEq(
            itemWithNestedValue.nested,
            session.createNativeQuery(mql, StructAggregateEmbeddableIntegrationTests.Plural.class).getSingleResult());
}

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.

1 participant