doesn't auto create index for entities that's mapped in the subpackage
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.
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.
I see. perhaps a note in the docs to highlight this? it confused me because the mapping part worked, though the index didn't.
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.
it was in here.
https://github.com/mongodb/morphia/issues/614
I did check first to make sure mapping subpackage would worked
+1. I knew it sounded familiar. Thanks.
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.
@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?
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 many thx for the fast reply. Great to hear that!
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 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.
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.
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.
@evanchooly I'm currently on trip, I will test it on sunday. thanks for looking into this
@wmacgyver oh, good! Maybe i'll hold off on the release then. I have some conference preparation I should be doing anyway.
@wmacgyver any update? If not, I'm inclined to close out 1.5.0 and move onward.
@evanchooly will give you an update in the next few hours
@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
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 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!