question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues converting to 2.x

See original GitHub issue

I have been running on Morphia for many years. I am trying to migrate my codebase from 1.6.x to 2.1 and am running into some issues. Primarily I cannot get it to initialize. In 1.6, I initialized like this:

Morphia morphia = new Morphia();

// auto-embedded indices are going away; this removed the warning messages in log
morphia.getMapper().getOptions().setDisableEmbeddedIndexes(true);

morphia.map(UserBean.class);
morphia.map(RequestBean.class);
morphia.map(PasswordResetBean.class);
morphia.map(NdcProduct.class);
morphia.map(Hcpcs.class);
morphia.map(LookupBean.class);
morphia.map(DiseaseBean.class);
morphia.map(DiseaseVersionBean.class);
morphia.map(DiseaseChangelogBean.class);
morphia.map(RxBean.class);
morphia.map(RxVersionBean.class);
morphia.map(RxChangelogBean.class);
morphia.map(GlossaryBean.class);
morphia.map(GlossaryVersionBean.class);
morphia.map(GlossaryChangelogBean.class);
morphia.map(StagingVersion.class);
morphia.map(StagingSchema.class);
morphia.map(StagingTable.class);
morphia.map(StagingSchemaHistory.class);
morphia.map(StagingTableHistory.class);

MongoClient mongoClient = new MongoClient(new MongoClientURI(uri));

Datastore datastore = morphia.createDatastore(mongoClient, db);

datastore.ensureIndexes();

Looking at the documentation at https://morphia.dev/morphia/2.1/quick-tour.html, I tried to initialize 2.1 like this:

Datastore datastore = Morphia.createDatastore(MongoClients.create("mongodb://localhost:27017"), "seerapi_unittest",
        MapperOptions.builder().disableEmbeddedIndexes(true).build());

datastore.getMapper().map(UserBean.class);
datastore.getMapper().map(RequestBean.class);
datastore.getMapper().map(PasswordResetBean.class);
datastore.getMapper().map(NdcProduct.class);
datastore.getMapper().map(Hcpcs.class);
datastore.getMapper().map(LookupBean.class);
datastore.getMapper().map(DiseaseBean.class);
datastore.getMapper().map(DiseaseVersionBean.class);
datastore.getMapper().map(DiseaseChangelogBean.class);
datastore.getMapper().map(RxBean.class);
datastore.getMapper().map(RxVersionBean.class);
datastore.getMapper().map(RxChangelogBean.class);
datastore.getMapper().map(GlossaryBean.class);
datastore.getMapper().map(GlossaryVersionBean.class);
datastore.getMapper().map(GlossaryChangelogBean.class);
datastore.getMapper().map(StagingVersion.class);
datastore.getMapper().map(StagingSchema.class);
datastore.getMapper().map(StagingTable.class);
datastore.getMapper().map(StagingSchemaHistory.class);
datastore.getMapper().map(StagingTableHistory.class);

datastore.ensureIndexes();

It fails on the first line with the following exception:

java.lang.ArrayStoreException: dev.morphia.mapping.codec.PrimitiveCodecRegistry

	at dev.morphia.mapping.Mapper.<init>(Mapper.java:95)
	at dev.morphia.DatastoreImpl.<init>(DatastoreImpl.java:68)
	at dev.morphia.Morphia.createDatastore(Morphia.java:48)
	at com.imsweb.seerapi.MorphiaConfigurationTest.testInit(MorphiaConfigurationTest.java:36)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)

I assume there is a problem with one of my mappings, but I have no idea which. I haven’t changed these mapping in a long time and the only changes I made to the mappings are the following (this was done in many classes, but I am showing just one example):

Removed noClassnameStored since it is no longer supported.

@Entity(value = "users", noClassnameStored = true)

became

@Entity(value = "users")

Changed the @Embedded annotation.

@Embedded("keys")
private Collection<UserKeyBean> _keys;

became

@Property("keys")
private Collection<UserKeyBean> _keys;

Is there a way to determine what mapping it does not like?

On a side note, I found a typo in the documentation for “Limiting and Skipping” (https://morphia.dev/morphia/2.1/querying.html#_limiting_and_skipping). The example looks like this:

   datastore.createQuery(Person.class)
    .iterator(new FindOptions()
	    .offset(1)
	    .limit(10))

However no offset method exists. The method name is skip in FindOptions.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ctmay4commented, May 1, 2021

I didn’t think of trying @Embedded. It worked. Thanks for the help!

0reactions
evanchoolycommented, May 1, 2021

You’ll need to mark it with @Entity ( or @Embedded) so that Morphia knows to map it out. 2.2 simplifies this a little by basically making @Entity the only annotation you need to use (@Embedded will be deprecated). Then for those types that will never serve as queryable types (i.e., mapped to a collection), you can skip the @Id annotation on a field. But that wont’ be available until 2.2 is out. ( I’m hoping in the next couple of weeks. there’s only 1 remaining issue.)

So try using @Embedded for now and that should resolve your issue here. If not, we can look at next steps but I’d be surprised if it that didn’t do the trick.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1.6 Unit Conversion Word Problems – Intermediate Algebra
1.6 Unit Conversion Word Problems. One application of rational expressions deals with converting units. Units of measure can be converted by multiplying ...
Read more >
How to Do Conversion Factors in a Word Problem - YouTube
... More:http://www.youtube.com/ehoweducationDoing conversion factors in a w... ... 0:00 / 2 :11• Live. •. •. Scroll for details ...
Read more >
Transforming data problem (article) - Khan Academy
How would this conversion impact the measures of center of spread in the data set? Let's look at a simpler example to think...
Read more >
Migrating from Log4j 1.x to 2.x - Apache Logging Services
Option 1: use the Log4j 1.x bridge (log4j-1.2-api). You may be able to convert an application to Log4j 2 without any code changes...
Read more >
2.6: Problem Solving and Unit Conversions
If you master the technique of applying conversion factors, you will be able to solve a large variety of problems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found