Skip to content
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 support for ObjectId #70

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

stIncMale
Copy link
Member

@stIncMale stIncMale self-assigned this Mar 17, 2025
Comment on lines +135 to +149
var expectedDoc = new BsonDocument()
.append("insert", new BsonString("items"))
.append(
"documents",
new BsonArray(List.of(new BsonDocument()
.append("string1", new BsonString("s1"))
.append("string2", new BsonString("s2"))
.append("int32", new BsonInt32(1))
.append("boolean", BsonBoolean.TRUE)
.append(
"stringAndObjectId",
new BsonArray(List.of(
new BsonString("array element"),
new BsonObjectId(new ObjectId(1, 2)))))
.append("objectId", new BsonObjectId(new ObjectId(2, 0))))));
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 way it is easier to express what exactly we are expecting than with a string.

@stIncMale stIncMale marked this pull request as ready for review March 27, 2025 05:10
@NathanQingyangXu
Copy link
Contributor

Looks great overall. Only some minor comments are left.

@NathanQingyangXu
Copy link
Contributor

Just found an edge case wherein explicit @JavaType annotation is used, the getById() testing case would fail:

@Entity
    @Table(name = "items")
    static class Item {
        @Id
        ObjectId id;

        @JavaType(ObjectIdJavaType.class)
        ObjectId v;
    }

@stIncMale
Copy link
Member Author

Regarding #70 (comment)

Just found an edge case wherein explicit @JavaType annotation is used, the getById() testing case would fail

This is because Hibernate ORM instantiates ObjectIdJavaType on its own in that case. Consequently, when it calls ObjectIdJdbcType.getBinder, the instance of ObjectIdJavaType passed as the javaType argument is not the same as ObjectIdJavaType.INSTANCE. I added the ObjectIdJavaType.equals/hashCode overrides to take this into account. However, applications can't explicitly use ObjectIdJavaType, ObjectIdJdbcType, because they are both internal. Are you aware of any reason to make them part of the API now?

Done in 60c7345.

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