-
Notifications
You must be signed in to change notification settings - Fork 12
Support native query without parameters #128
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
6572fbb
to
72dd7e0
Compare
|
||
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; |
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.
I made MqlType
package-access, as it does not need to be public
.
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.
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(); |
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.
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 { |
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 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.
72dd7e0
to
510ae1f
Compare
@Table(name = COLLECTION_NAME) | ||
@SqlResultSetMapping( | ||
name = ItemWithFlattenedValue.MAPPING_FOR_FLATTENED_VALUE, | ||
columns = { |
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.
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.
02c39c7
to
51b953e
Compare
51b953e
to
6fb9e8c
Compare
@Table(name = COLLECTION_NAME) | ||
static class ItemWithArrayAndCollectionValues { | ||
@SqlResultSetMapping( | ||
name = ItemWithArrayAndCollectionValues.MAPPING_FOR_ITEM, |
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.
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() { |
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.
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());
}
HIBERNATE-60