Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wmacgyver opened this issue Oct 9, 2017 · 21 comments
Closed
Labels
Milestone

Comments

@wmacgyver
Copy link

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.

@evanchooly
Copy link
Member

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.

@wmacgyver
Copy link
Author

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

@evanchooly
Copy link
Member

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.

@wmacgyver
Copy link
Author

it was in here.

#614

I did check first to make sure mapping subpackage would worked

@evanchooly
Copy link
Member

+1. I knew it sounded familiar. Thanks.

@hdoeleman
Copy link

hdoeleman commented Feb 16, 2018

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 evanchooly added the bug label Mar 31, 2019
@evanchooly evanchooly added this to the 1.5.0 milestone Mar 31, 2019
@leeloo1
Copy link

leeloo1 commented Apr 10, 2019

@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?

@evanchooly
Copy link
Member

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.

@leeloo1
Copy link

leeloo1 commented Apr 10, 2019

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

@evanchooly
Copy link
Member

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.

@leeloo1
Copy link

leeloo1 commented Apr 11, 2019

@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.

@evanchooly
Copy link
Member

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.

@leeloo1
Copy link

leeloo1 commented Apr 11, 2019

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.

@wmacgyver
Copy link
Author

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

@evanchooly
Copy link
Member

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

@evanchooly
Copy link
Member

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

@wmacgyver
Copy link
Author

wmacgyver commented Apr 15, 2019

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

@wmacgyver
Copy link
Author

@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

@evanchooly
Copy link
Member

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.

@wmacgyver
Copy link
Author

@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!

@evanchooly
Copy link
Member

excellent! thanks for double checking that for me. I'll close this out and release 1.5.0 tomorrowish then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants