[JAVA-1102] DBRefBase should implement Serializable Created: 31/Jan/14 Updated: 03/Apr/14 Resolved: 28/Feb/14 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 2.9.3 |
| Fix Version/s: | 2.12.0, 3.0.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Steven Sheehy | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
DBRef and DBRefBase should implement Serializable to match all the other supported BSON types. Implementation note: Since DB instances are not serializable, the DB property is marked as transient and will not survive deserialization. As a result, deserialized DBRef instances can not be fetched using the fetch method. |
| Comments |
| Comment by Jeffrey Yemin [ 01/Mar/14 ] |
|
Can you post your compiler output? 2.12.0-rc0 should for the most part be binary compatible with 2.9.3. It does deprecate a lot of methods, but none are removed yet. Thanks, |
| Comment by Steven Sheehy [ 28/Feb/14 ] |
|
Tried to upgrade the java driver on our codebase, but there were too many API changes in between the version we had and 2.12.0-rc0. It would require a lot of changes to test it out. However, I did review the code changes and it was the same as I made locally to get it to work. So I can confirm it fixes the issue. |
| Comment by Githook User [ 28/Feb/14 ] |
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: |
| Comment by Jeffrey Yemin [ 27/Feb/14 ] |
|
Hi Steven, Can you test the fix for this issue in 2.12.0-rc0, available either on github or Maven Central. Thanks, |
| Comment by Jeffrey Yemin [ 13/Feb/14 ] |
|
Implemented in master. 3.0 next. |
| Comment by Githook User [ 13/Feb/14 ] |
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: |
| Comment by Steven Sheehy [ 07/Feb/14 ] |
|
3.0.x driver doesn't even have fetch, so should be trivial to implement Serializable there: https://github.com/mongodb/mongo-java-driver/blob/3.0.x/driver/src/main/org/mongodb/DBRef.java I agree that it may break the contract of DBRef.fetch(), but only after deserialization occurs. Considering right now it cannot serialize/deserialize at all, it would not break anyone's code to not support fetch after deserializing (since there code would break before then). If need be, a setDB() method can be added so that users can set it if need be after deserializing. DBRef is already not immutable due to the _pointedTo and adding this method would not break API compatibility. |
| Comment by Jeffrey Yemin [ 04/Feb/14 ] |
|
I'll have to think about this a bit more. While it make work for you, it does break the contract of DBRef to not be able to fetch, so it could lead to surprising results (though admittedly less surprising that not being able to serialize at all.). |
| Comment by Steven Sheehy [ 04/Feb/14 ] |
|
We just marked the _db field as transient to indicate it should not be serialized in our local code. The DB is for us an optional field since it is only used during calls to fetch(). Since we don't use fetch, it is not an issue for us. The MongoDB java driver also does not serialize the _db field when writing the DBRef to the database, so I don't think standard Java serialization needs to do anything different. |
| Comment by Jeffrey Yemin [ 02/Feb/14 ] |
|
Hi Steven, Unfortunately I don't see a way for DBRefBase to be serializable, due to the _db field of type DB. When deserializing there is no way to reconstruct that reference, as it would require a Mongo instance to do so. |
| Comment by Steven Sheehy [ 31/Jan/14 ] |
|
We need to be able to take DBObjects and be able to place them on a JMS queue for asynchronous processing. The JMS serialization will fail with a NotSerializableException if the DBObject contains a DBRef because that class does not implement Serializable. |