Comments (2)
Hi,
You have 2 options here:
- Use
IMetadataDictionary metadataFor = session.advanced().getMetadataFor(map);
@Test
public void mapAsEntity() {
try (IDocumentStore store = new DocumentStore("http://live-test.ravendb.net", "Java")) {
store.getConventions().registerIdConvention(Map.class, (String dbName, Map entity) -> {
// concat with '/' to automatically generate document id postfix
return (String) entity.get("collection") + "/";
});
store.initialize();
try (IDocumentSession session = store.openSession()) {
Map<String, Object> map = new HashMap<>();
map.put("collection", "Person");
map.put("age", 23);
map.put("name", "Ada Lovelace");
map.put("subdocument", Collections.singletonMap("doc", "map"));
session.store(map);
IMetadataDictionary metadataFor = session.advanced().getMetadataFor(map);
metadataFor.put(Constants.Documents.Metadata.COLLECTION, "Person");
metadataFor.put(Constants.Documents.Metadata.RAVEN_JAVA_TYPE, "YouCanOverrideJavaTypeHere");
session.saveChanges();
}
}
}
- Or register
store.addBeforeStoreListener
:
@Test
public void mapAsEntityOnBeforeStore() throws Exception {
try (IDocumentStore store = new DocumentStore("http://live-test.ravendb.net", "Java")) {
store.getConventions().registerIdConvention(Map.class, (String dbName, Map entity) -> {
// concat with '/' to automatically generate document id postfix
return entity.get("collection") + "/";
});
store.addBeforeStoreListener((sender, event) -> {
IMetadataDictionary documentMetadata = event.getDocumentMetadata();
documentMetadata.put(Constants.Documents.Metadata.COLLECTION, "People");
});
store.initialize();
try (IDocumentSession session = store.openSession()) {
Map<String, Object> map = new HashMap<>();
map.put("collection", "Person");
map.put("age", 23);
map.put("name", "Ada Lovelace");
map.put("subdocument", Collections.singletonMap("doc", "map"));
session.store(map);
session.saveChanges();
}
}
}
from ravendb-jvm-client.
from ravendb-jvm-client.
Related Issues (20)
- Error during use a certificate for store data HOT 5
- Scala support HOT 2
- Connecting to RavenDB server using a self-signed certificate HOT 2
- Kotlin deserialization - SOLVED HOT 1
- Unable to find class by name in Quarkus CDI context - SOLVED HOT 8
- NullPointerException from SubscriptionWorker HOT 2
- SubscriptionWorker does not handle "redirects" correctly HOT 9
- Error from subscription: `Server returned illegal type message when expecting connection status, was:ERROR` HOT 4
- Non blocking client for Java HOT 4
- Duplicate condition == dead code? HOT 2
- Comment documentation welcome? HOT 1
- Manually set up test server? HOT 3
- Add a DocumentStore.Builder HOT 6
- BUG: TestDriver runtime version is lower than installed version but won't run HOT 6
- Should Throw Error When No ID Field Exists/Is Specified HOT 3
- Suggestion: More Intuitive Way to Specify Identifier Property HOT 3
- Can't Use UUID Field as Identifier (even though a uuid can be a string) HOT 3
- StackOverflowError in data subscriptions when RavenDB server becomes unhealthy HOT 3
- 'Working with secured server' issue and resolution HOT 1
- Data subscriptions throw an IllegalStateException: "Session can only be opened once per each Subscription batch" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ravendb-jvm-client.