-
Notifications
You must be signed in to change notification settings - Fork 49
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
Sporadic DuplicateAttributeNames error during Model enhancement if auto timestamp is enabled #103
Comments
this looks weird. When a class is enhanced, meaning it is already loaded Do you have a sample can reproduce the error you described? On Mon, Jan 28, 2013 at 2:14 PM, Mike Spross [email protected]:
|
I thought it was strange as well, and I assumed the same thing (that the classloader would load the parent class before the subclass, so it should be enhanced before the subclass). It started happening to me "all of a sudden" on my fork of the project: I thought one of my code changes was causing the problem, but now I am not so sure, because I could see from the Play application logs that For me, the issue was happening with the I think the problem is that the classloader has -- at least in some cases -- already loaded all of the classes when Play runs the class enhancers: therefore, I think the classes are enhanced in whatever order Play stores the classes in the I ran I would like to try to reproduce this with a "clean" copy of your repository, but I am having trouble building the current master branch (in my fork I made some changes so I could build it in my environment, but I would like to try with the current code in master to verify that it's not just my fork that has this problem). I tried this:
But I get compile errors related to javassist (I am using play-1.2.5, which uses an older version of javassist [3.9.0GA] compared to what was originally in 1.2.5rc1). What is the recommended/preferred way to build the code so that I can try to reproduce this issue? |
Also, here is an excerpt from the Play log when I ran my forked version of the code (although I still want to try with the original code), just to demonstrate that the classes are being enhanced in a different order than expected. In this example, I had put
For some reason,
If I change the name of This is why I think this has more to do with Play than my fork, but I am curious to see what happens with the master code in your repository here to see if the same issue occurs on my machine. Maybe it has to do with the version of Play and/or the JDK that I have installed. My fork also has some additional classes that I added to the I will try a few more things on my end. I'm also researching a bit more about how classloading is supposed to work in Java, to see if it is "normal" for classes to loaded out-of-order. |
It seems that Play 1.2.5 doesn't enhance classes in a fixed, guaranteed order. In some cases, this can cause a DuplicateAttributeNames validation error to occur (within Morphia itself) if the auto timestamp feature is turned on.
Specifically, this can happen if you create an entity class A, and a subclass B that extends A (for example, LifeCycle and LifeCycle.Child in the play-morphia
unit-tests
project).If the subclass is enhanced before the superclass, the _created and _modified fields get added to the subclass by MorphiaEnhancer, and they will also be added to the superclass.
This creates a problem for Morphia's Mapper class, because it will see these fields on the subclass and on the superclass and throw a ConstraintViolationException because it thinks they are duplicate field declarations.
If the superclass is enhanced before the subclass, this issue doesn't occur, because if the superclass already has these fields, PlayMorphia will not add them to the subclass, and Morphia will therefore only see one copy of these fields.
This issue happens in play-morphia 1.2.12 (which uses morphia-1.00-20110403.jar).
The text was updated successfully, but these errors were encountered: