I'm trying to create a MongoDB database using Morphia, however when I create the Morphia Datastore, I get the following error:
[18:33:13 WARN]: java.lang.ArrayStoreException: dev.morphia.mapping.codec.PrimitiveCodecRegistry
[18:33:13 WARN]: at TerraNova-1.0-ALPHA-all.jar//dev.morphia.mapping.Mapper.<init>(Mapper.java:96)
[18:33:13 WARN]: at TerraNova-1.0-ALPHA-all.jar//dev.morphia.DatastoreImpl.<init>(DatastoreImpl.java:70)
[18:33:13 WARN]: at TerraNova-1.0-ALPHA-all.jar//dev.morphia.Morphia.createDatastore(Morphia.java:49)
[18:33:13 WARN]: at TerraNova-1.0-ALPHA-all.jar//dev.morphia.Morphia.createDatastore(Morphia.java:60)
[18:33:13 WARN]: at TerraNova-1.0-ALPHA-all.jar//io.github.vyketype.terranova.database.Database.init(Database.java:49)
[18:33:13 WARN]: at TerraNova-1.0-ALPHA-all.jar//io.github.vyketype.terranova.TerraNova.onEnable(TerraNova.java:34)
and the rest of the stack trace leading to the Java library stuff...
I've researched the cause of this exception and I understood that this is an issue concerning arrays, but I'm not using any arrays. This error is happening when I'm creating the Datastore. Here is some of my code.
private MongoClient client;
private Datastore datastore;
public void init() {
String confString = Objects.requireNonNull(instance.getConfig().getString("database"));
ConnectionString connectionString = new ConnectionString(confString);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.uuidRepresentation(UuidRepresentation.STANDARD)
.build();
client = MongoClients.create(settings);
datastore = Morphia.createDatastore(client, "terranova-test");
datastore.ensureIndexes();
datastore.getMapper().map(User.class);
}
All of this code is in a Database
class. I am not sure what I am doing wrong and why, in particular, I am getting an ArrayStoreException
. This error has been bugging me for quite some time now, all help is appreciated!
CodePudding user response:
The last time I saw this happen was due to having conflicting versions of either Morphia or the driver. I'd start looking there.