Sent from my iPad
It is best to actually use a type when you can. Since it is in an
@Embedded class it is probably treating it as a complex type and
expecting it to be stored as such; then when it is just a Double there
is a problem.
You might call this a bug -- I'm leaning that way; it is a little
confusing for the system to guess how it should load the data when it
is declared as Object and it can do a better job, clearly.
I think in your case using @Property on the "private Object value"
declaration will fix the problem.
I'll create an issue to investigate if we can simplify this and not
require any special hints. At this point unless you mark it as
@Serialized/@Reference everything is embedded.
2010/12/29 Valentín Moreno <vale...@gmail.com>:
> Solution (@Property) that you proposed works, however I don't understand
> why..I mean, I guess that if you don't include the annotation Property,
> Morphia should does the same that without it (of course rename is not
> allowed in this case). What is the additional functionality of this
> annotation?
This really has to do with the old dichotomy of @Property/@Embedded
from versions of yore.
@Property tells the mapper that the values will be simple like
String/Double/Integer and not a complex (@Embedded) object which is
stored as embedded document in mongodb.
> I am still not understanding why if I use a complex type
> (MetricResultParameter), I cant use Object as attribute for this complex
> type. I know the best way to do it is setting a fixed type, however, in my
> case, flexibility to have different object types on this field is very
> useful, it avoids me to create different attributes object types with the
> same finality. I am agree with you when you said I might call it a bug,
> Anyway, thank you very much.
You can also create multiple classes and use an interface (or base
abstract), but that might be too complicated.
interface MetricResultParameter {}
class MetricResultStringParameter {
String name;
String value;
}
class MetricResultDoubleParameter {
String name;
Double value;
2010/12/29 Valentín Moreno <vale...@gmail.com>:
> Dear Scott:This really has to do with the old dichotomy of @Property/@Embedded
> First of all, I want to thank you for your quick reply.
> Solution (@Property) that you proposed works, however I don't understand
> why..I mean, I guess that if you don't include the annotation Property,
> Morphia should does the same that without it (of course rename is not
> allowed in this case). What is the additional functionality of this
> annotation?
from versions of yore.
@Property tells the mapper that the values will be simple like
String/Double/Integer and not a complex (@Embedded) object which is
stored as embedded document in mongodb.
You can also create multiple classes and use an interface (or base
> I am still not understanding why if I use a complex type
> (MetricResultParameter), I cant use Object as attribute for this complex
> type. I know the best way to do it is setting a fixed type, however, in my
> case, flexibility to have different object types on this field is very
> useful, it avoids me to create different attributes object types with the
> same finality. I am agree with you when you said I might call it a bug,
> Anyway, thank you very much.
abstract), but that might be too complicated.
interface MetricResultParameter {}
class MetricResultStringParameter {
String name;
String value;
}
class MetricResultDoubleParameter {
String name;
Double value;
}
In practice that is less likely that an Object is going to be
@Property. But really I think there shouldn't be a need to use
@Property ever; we can find another way to set the name mapping.
> this should be the default action.
> If your attribute is embedded or referenced and you don't include the proper
> annotation is a fault from the coder.
We have had this discussion before but I feel @Property/@Embedded
should be the default, and it pretty much is now. There are a few
corner cases like Object in an embedded class where it can be a little
confusing what should be done (esp. when load data from mongodb). I'd
like to see it where almost all the annotation are optional, which is
also pretty much true now.