Closed cmitchell closed 1 year ago
This is by design. You are not forced to use id
field, and if you don't specify one (or override the defaults), RavenDB will manage the id for you internally.
You can get the document id after the store
using session.advanced().getDocumentId(testOrder);
@ayende Thanks for the clarification. It would be more dev friendly if this were prominently documented somewhere (I culdn't find this on your website), and even better if a Warning got logged when you call store that it's being managed internally.
That is a feature, not an issue. There is a valid use case for not making the entity id as a field on the entity. This is the same as Hibernate or JPA model. For example, in Hibernate, see: https://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/Session.html#getIdentifier(java.lang.Object)
Hi,
I think I've found a few bugs regarding setting the Identifer field.
If your model object does not have have a
Id
field, and you have not set a different field to be used as theId
by callingfindIdentifierProperty
you don't get an error when you store the object.In the sample code below, the Order object does NOT have an
Id
field. It has a uuid field, but I haven't calledfindIdentifierProperty
. I should get an error whensession.store()
is calleld but I don't.Code (Using Junit5 with Spring) The Configuration (Setup)
The Test
The output -- no error is ever thrown and my uuid field (which I understand RavenDB doesn't know is what I want to use as an Id) is still null. I made sure that errors were NOT hidden by my logging level. If I had any assertions in this test, it would fail. The point is, I think this scenario should throw an error, otherwise in actual non-test code I might think everything is ok.