Comment on EmbeddedAnnotation in morphia

8 views
Skip to first unread message

mor...@googlecode.com

unread,
Nov 17, 2010, 10:23:20 AM11/17/10
to morphia...@googlegroups.com
Comment by pac.homework:

{{{
@Embedded(name = "blog_comments")
private List<Comment> comments;
}}}

The Embedded annotation's parameter should be 'value', not 'name.

For more information:
http://code.google.com/p/morphia/wiki/EmbeddedAnnotation

mor...@googlecode.com

unread,
May 30, 2011, 1:56:26 AM5/30/11
to morphia...@googlegroups.com
Comment by n...@transmachina.com:

Is there some annotation for a parent field? For example, if we added a
field "private Hotel hotel" into the Address class? I have a case where I
need to be able to reference the parent object, but I dont want to persist
a DBRef to the parent unnecessarily.

mor...@googlecode.com

unread,
Nov 2, 2011, 3:50:42 AM11/2/11
to morphia...@googlegroups.com
Comment by killyous...@gmail.com:

How do you change a Address in the Hotel ?
for example
@Entity
public class Hotel {

@Id
private String id;

private String name;
private int stars;

@Embedded
private Hotel Hotel;

// ... getters and setters
}

 If this is the data structure and bottom to modfiy the address ?

mor...@googlecode.com

unread,
Feb 9, 2012, 12:00:41 PM2/9/12
to morphia...@googlegroups.com
Comment by lidde...@gmail.com:

I assume you meant to say

<code language="java">
@Entity
public class Hotel {

@Id private String id;

private String name; private int stars;

@Embedded private *Address address*;

// ... getters and setters

}
</code>

Where Hotel stores an embedded Address (not another Hotel).

You would interact with your objects just like you normally would:

<code language="java">
Address address = myHotel.getAddress(); // assumes getAddress() getter in
Hotel class
address.setStreet("100 Pleasant Ave"); // assumes setStreet() setter in
Address class
address.setCountry("United States"); // assumes setCountry() setter in
Address class
</code>

Etc, etc. You get the idea. Then, to save your changes:

<code language="java">
datastoreReference.save(myHotel);
</code>

mor...@googlecode.com

unread,
Feb 9, 2012, 12:04:43 PM2/9/12
to morphia...@googlegroups.com
Comment by lidde...@gmail.com:

I assume you meant to say

{{{
@Entity public class Hotel {

@Id private String id;

private String name; private int stars;

@Embedded private *Address address*;

// ... getters and setters

}
}}}

Where Hotel stores an embedded Address (not another Hotel).

You would interact with your objects just like you normally would:

{{{


Address address = myHotel.getAddress(); // assumes getAddress() getter in
Hotel class address.setStreet("100 Pleasant Ave"); // assumes setStreet()
setter in Address class address.setCountry("United States"); // assumes
setCountry() setter in Address class
}}}

Etc, etc. You get the idea. Then, to save your changes:

{{{
datastoreReference.save(myHotel);

mor...@googlecode.com

unread,
Feb 9, 2012, 12:08:50 PM2/9/12
to morphia...@googlegroups.com
Comment by lidde...@gmail.com:

I assume you meant to say

{{{
@Entity
public class Hotel {

@Id private String id;

private String name; private int stars;

@Embedded private Address address;

// ... getters and setters

}
}}}

Where Hotel stores an embedded _*Address*_ (not another Hotel).

mor...@googlecode.com

unread,
Jun 28, 2012, 10:44:41 PM6/28/12
to morphia...@googlegroups.com
Comment by tiedangy...@gmail.com:

Can i use embedded annotation for an entity as following (does morphia
ignore the @id annotation in this case)?
{{{
@Entity
public class Hotel {
@Id private ObjectId id;

private String name; private int stars;

@Embedded private Address address;

// ... getters and setters
}

@Entity
public class Address {
@Id private ObjectId id;

private String street;
private String country;

// ... getters and setters
}
}}}

mor...@googlecode.com

unread,
Aug 9, 2012, 6:52:55 AM8/9/12
to morphia...@googlegroups.com
Comment by niko.j.m...@gmail.com:

I've used a normal entity like that with embedded annotation. It will all
be saved ok, but seems like _id field is always added to embedded stuff too.

Actually, at the moment I'm having a problem with those _id-fields - If I
have 3 hotels in same building in 1 address, but they have for example
different door letters, a, b and c, all those hotels will always be
returned with address of letter "c". If I delete _id fields from embedded
addresses, everything works ok. Any help would be appreciated. I'm using
Grails with Morphia Plugin.

mor...@googlecode.com

unread,
Oct 19, 2013, 8:58:31 PM10/19/13
to morphia...@googlegroups.com
Comment by har...@redmart.com:

You can remove @Entity and @Id annotations from Embedded classes
Reply all
Reply to author
Forward
0 new messages