morphia icon indicating copy to clipboard operation
morphia copied to clipboard

doesn't auto create index for entities that's mapped in the subpackage

Open wmacgyver opened this issue 9 years ago • 21 comments

while morphia will map correctly for subpackage

.mapPackage("package")

it will map all the classes in package.subpackage

but any class in package.subpackage that has @Indexes is not processed.

but if I add

.mapPackage("package.subpackage"

the .ensureIndexes call create the indexes for subpackage classes correctly.

wmacgyver avatar Oct 09 '17 05:10 wmacgyver

subpackages aren't actually a thing in java. "com.foo.bar" is a distinct entity from "com.foo" and is not nested under. As such, there's no cheap discoverability of these "nested" packages short of classpath scanning. In short, you'll have to call mapPackage() for each package you're wanting to map.

evanchooly avatar Oct 09 '17 06:10 evanchooly

I see. perhaps a note in the docs to highlight this? it confused me because the mapping part worked, though the index didn't.

wmacgyver avatar Oct 09 '17 17:10 wmacgyver

Now, it's interesting you bring that up. Even as I was writing about how terrible it would be for performance, there was a part of me that was remembering that ... something already did that. That should probably be made consistent either way. I'll poke around and see. It's been a long time since I've been in this code.

evanchooly avatar Oct 09 '17 17:10 evanchooly

it was in here.

https://github.com/mongodb/morphia/issues/614

I did check first to make sure mapping subpackage would worked

wmacgyver avatar Oct 09 '17 17:10 wmacgyver

+1. I knew it sounded familiar. Thanks.

evanchooly avatar Oct 09 '17 17:10 evanchooly

I have a class that has some Morphia index annotations. When mapped with mapPackage(), the indexes were created correctly when starting the application in Tomcat. Not so in JBoss 6.4.10.GA however. Made it work by mapping the class explicitly rather than the package. Can this be fixed? It is less ideal to have to map every class explicitly.

hdoeleman avatar Feb 16 '18 15:02 hdoeleman

@evanchooly first of all many thanks for the revival and reactivation of the project. And your intensive participation and support. We are users of morphia from the very beginning. Since this seems to be the last issue for the 1.5 release, where we are all eagerly awaiting it. Do you have a time vision (release date in mind) for the 1.5 release?

leeloo1 avatar Apr 10 '19 16:04 leeloo1

This is the last issue tagged for 1.5.0. Ideally, I'll fix this tonight or at least this week and by next week at the latest we'd have a 1.5.0 published.

evanchooly avatar Apr 10 '19 19:04 evanchooly

@evanchooly many thx for the fast reply. Great to hear that!

leeloo1 avatar Apr 10 '19 21:04 leeloo1

Can you test with a 1.5.0-SNAPSHOT build? I wrote a test first to show the problem before fixing it. But my test works here without any changes to Morphia. Make sure you've set mapSubPackages to true on your MapperOptions.

evanchooly avatar Apr 11 '19 01:04 evanchooly

@evanchooly I would like to support and put it into our backlog, but we will probably not be able to give feedback so quickly, because unfortunately the change will take a little longer with us. Hopefully e.g. the issue creator can support here.

leeloo1 avatar Apr 11 '19 10:04 leeloo1

then what I might do is mark the issue as fixed and close out 1.5.0. If there's some nuance to the issue I've missed, it could always be corrected in a 1.5.1.

evanchooly avatar Apr 11 '19 11:04 evanchooly

Yes, I think this is a valid approach. If we then find anything during our migration to 1.5, we would report it. Which could then be included in 1.5.1 bug fix release.

leeloo1 avatar Apr 11 '19 12:04 leeloo1

@evanchooly I'm currently on trip, I will test it on sunday. thanks for looking into this

wmacgyver avatar Apr 11 '19 16:04 wmacgyver

@wmacgyver oh, good! Maybe i'll hold off on the release then. I have some conference preparation I should be doing anyway.

evanchooly avatar Apr 11 '19 17:04 evanchooly

@wmacgyver any update? If not, I'm inclined to close out 1.5.0 and move onward.

evanchooly avatar Apr 15 '19 02:04 evanchooly

@evanchooly will give you an update in the next few hours

wmacgyver avatar Apr 15 '19 02:04 wmacgyver

@evanchooly sadly, it didn't work

first I tested it using morphia 1.3.2, if I add map of sub package, it created indexes for them correctly. if I don't. it didn't work

then I tested using dev.morphia.morphia:core:1.5.0-SNAPSHOT, with mongo driver 3.10.1

without mapping the subpackage, it does NOT create the indexes but if I I add the mapping statement for subpackage, it created the index

wmacgyver avatar Apr 15 '19 03:04 wmacgyver

well, right. unless you map the subpackage, it's not going to know about the classes to create the indexes. The indexing is driven by the classes that have been mapped.

evanchooly avatar Apr 15 '19 03:04 evanchooly

@evanchooly no no, I take that back. it worked.

I did the MapperOptions.setMapSubPackages(true); part wrong

I just fixed it, and now with dev.morphia.morphia:core:1.5.0-SNAPSHOT, with mongo driver 3.10.1

even without explict mapping subpackage, the indexes still are created.

so your fix worked yay!

wmacgyver avatar Apr 15 '19 03:04 wmacgyver