Suppress ClassName in Morphia MongoDB Objects

653 views
Skip to first unread message

Mike

unread,
Jun 11, 2010, 12:13:24 PM6/11/10
to Morphia
http://code.google.com/p/morphia/issues/detail?id=17

Is it possible to suppress ClassName in the latest snapshot? How?

Thanks.

Scott Hernandez

unread,
Jun 11, 2010, 12:22:05 PM6/11/10
to mor...@googlegroups.com
No, they are needed in some places. In the case where the type is not
known via reflection we must store the classname to be able to create
an object.

We should be able to get rid of the classname for the entity
(root-document) and replace it with a discriminator when we add
support for polymorphism. That will make things a little nicer.

Is this causing a problem for you?

Michael Moss

unread,
Jun 11, 2010, 12:27:05 PM6/11/10
to mor...@googlegroups.com
Not a problem per se, just wondering what I should do. I don't have a polymorphic object structure that I am persisting and storing className on millions of objects seems verbose, so I'd like to try to avoid it. I *thought* thats what this ticket might be addressing and wasn't sure how I could disable the className from persisting.

Scott Hernandez

unread,
Jun 11, 2010, 12:35:30 PM6/11/10
to mor...@googlegroups.com
You are correct. It was created to address that issue. It used to be
true that *every* object (including embedded ones) stored a classname.
We cleaned that up a bit, but there were some issues when it came to
poly impl.

I will create a new ticket for this issue. The poly stuff isn't bound
to this issue; they can be separated.

Mike

unread,
Jun 30, 2010, 9:58:28 AM6/30/10
to Morphia
Hey, Scott.

May we get a quick update on this? Was the new ticket created to track
this issue?

Specifically, if we have a top level object:

package com.foo.bar;

import ...

@Entity("mycollection")
public class MyObject {
}

We want to be able to suppress "className" : "com.foo.bar.MyObject" on
every document in the collection.

Thanks.

On Jun 11, 12:35 pm, Scott Hernandez <scotthernan...@gmail.com> wrote:
> You are correct. It was created to address that issue. It used to be
> true that *every* object (including embedded ones) stored aclassname.
> We cleaned that up a bit, but there were some issues when it came to
> poly impl.
>
> I will create a new ticket for this issue. The poly stuff isn't bound
> to this issue; they can be separated.
>
>
>
> On Fri, Jun 11, 2010 at 9:27 AM, Michael Moss <michael.m...@gmail.com> wrote:
> > Not a problem per se, just wondering what I should do. I don't have a
> > polymorphic object structure that I am persisting and storingclassNameon
> > millions of objects seems verbose, so I'd like to try to avoid it. I
> > *thought* thats what this ticket might be addressing and wasn't sure how I
> > could disable theclassNamefrom persisting.
>
> > On Fri, Jun 11, 2010 at 12:22 PM, Scott Hernandez <scotthernan...@gmail.com>
> > wrote:
>
> >> No, they are needed in some places. In the case where the type is not
> >> known via reflection we must store theclassnameto be able to create
> >> an object.
>
> >> We should be able to get rid of theclassnamefor the entity
> >> (root-document) and replace it with a discriminator when we add
> >> support for polymorphism. That will make things a little nicer.
>
> >> Is this causing a problem for you?
>
> >> On Fri, Jun 11, 2010 at 9:13 AM, Mike <michael.m...@gmail.com> wrote:
> >> >http://code.google.com/p/morphia/issues/detail?id=17
>
> >> > Is it possible to suppressClassNamein the latest snapshot? How?
>
> >> > Thanks.

Scott Hernandez

unread,
Jun 30, 2010, 10:11:50 AM6/30/10
to mor...@googlegroups.com
I added a temporary option like this @Entity(noClassnameStored=true);
I will push that out in the next 0.94 snapshot.

This will change in the near future once the Poly stuff works.

Mike

unread,
Jun 30, 2010, 10:24:52 AM6/30/10
to Morphia
Cool. Will the upcoming poly change be backwards compatible assuming
we go with 'noClassnameStored=true' once it's available in 0.94
snapshot? Any estimates on 0.94-RELEASE release date?

We are about to go live with a collection that will store billions of
docs, so getting the className out of there before go live would be
ideal, especially since Mongo 1.4 doesn't yield on update!

Thanks again.

-Mike

Scott Hernandez

unread,
Jun 30, 2010, 10:32:33 AM6/30/10
to mor...@googlegroups.com
It is up there now if you want to use it.

On Wed, Jun 30, 2010 at 7:24 AM, Mike <michae...@gmail.com> wrote:
> Cool. Will the upcoming poly change be backwards compatible assuming
> we go with 'noClassnameStored=true' once it's available in 0.94
> snapshot? Any estimates on 0.94-RELEASE release date?

If there are going to be changes then noClassnameStored will get
deprecated and then removed (after a version or two), but the
functionality will exist somewhere. It is temporary since we are not
sure how it will surface in future versions with other features
involved. The best answer I can give is "maybe", but probably not in
the long run.

> We are about to go live with a collection that will store billions of
> docs, so getting the className out of there before go live would be
> ideal, especially since Mongo 1.4 doesn't yield on update!

Yeah, that will be rough until 1.6; I'm sure you can't wait :)

Reply all
Reply to author
Forward
0 new messages