Describe the bug
When dev.morphia.Datastore shared across thread, I get Two entities have been mapped using the same discriminator value.
To Reproduce
Steps to reproduce the behavior:
-
Create a sample collection and create the datastore.
Datastore datastore = Morphia.createDatastore(mongo, dbName);
datastore.ensureIndexes();
if(this.packages != null){
for (String packageString : packages) {
datastore.getMapper().map(packageString);
}
}
-
Create a runnable class and pass the data store and id parameter. In run method load the data from the collection using id and datastore.
class Task implements Runnable {
private String id;
private Datastore mongoDatastore;
Task(String id, Datastore mongoDatastore) {
this.id = id;
this.mongoDatastore = mongoDatastore;
}
@OverRide
public void run() {
Sample result = mongoDatastore.find(Sample.class).filter(Filters.eq("_id", id)).first();
if(result == null){
System.out.println("Result is null");
}else {
System.out.println(result.toString());
}
}
}
-
Write main method, create ExecutorService and try to load different documents.
ExecutorService executor = Executors.newFixedThreadPool(10);
executor.execute(new Task("ABC12345", mongoDatastore));
executor.execute(new Task("ABC123456", mongoDatastore));
I get Two entities have been mapped using the same discriminator value.
Try two scenario
- When ids are valid id from collection
- Try some invalid ids where collection return null.
Describe the bug
When dev.morphia.Datastore shared across thread, I get Two entities have been mapped using the same discriminator value.
To Reproduce
Steps to reproduce the behavior:
Create a sample collection and create the datastore.
Datastore datastore = Morphia.createDatastore(mongo, dbName);
datastore.ensureIndexes();
if(this.packages != null){
for (String packageString : packages) {
datastore.getMapper().map(packageString);
}
}
Create a runnable class and pass the data store and id parameter. In run method load the data from the collection using id and datastore.
class Task implements Runnable {
private String id;
private Datastore mongoDatastore;
Task(String id, Datastore mongoDatastore) {
this.id = id;
this.mongoDatastore = mongoDatastore;
}
@OverRide
public void run() {
}
}
Write main method, create ExecutorService and try to load different documents.
ExecutorService executor = Executors.newFixedThreadPool(10);
executor.execute(new Task("ABC12345", mongoDatastore));
executor.execute(new Task("ABC123456", mongoDatastore));
I get Two entities have been mapped using the same discriminator value.
Try two scenario