{{{
@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
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.
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>
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);
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).