How to get embedded entity from an Entity

52 views
Skip to first unread message

Cole Abbeduto

unread,
Oct 23, 2017, 2:35:50 PM10/23/17
to Google App Engine
Language: Java 8

So I have a datastore set up and one of the KIND's has an Embedded Entity as a property.

Everything works perfectly fine until you want to turn that entity back into the object because for some reason there doesn't seem to be a way to get an embedded entity from an entity object. 

To get any particular type from a given Entity entity, you use:
entity.getType(String nameOfProperty)

So to get an Entity, you would assume you would use:
entity.getEntity(String nameOfProperty), but for some reason it returns something called a FullEntity<IncompleteKey> and there dosen't seem to be a way to turn that into a normal Entity.

Along with this I found documentation that said another way to get an Embedded entity was
(YourTypeHere) entity.getProperty(String nameOfPosition)
and this would be fine...if it was an actualy method, but for some reason it isn't because I guess the documentation is out of date. 

Another method I saw was to use the EmbeddedEntity object...which doesn't exist either.

Could somebody please tell me what I need to do to get an Entity object from withinside of another Entity object???

Kenworth (Google Cloud Platform)

unread,
Oct 23, 2017, 4:54:05 PM10/23/17
to Google App Engine
Based on this documentation, here is how you should embed and retrieve an entity:

Embed / Create : 

// Entity employee = ...;
EmbeddedEntity embeddedContactInfo = new EmbeddedEntity();

embeddedContactInfo.setProperty("homeAddress", "123 Fake St, Made, UP 45678");
embeddedContactInfo.setProperty("phoneNumber", "555-555-5555");
embeddedContactInfo.setProperty("emailAddress", "te...@example.com");

employee.setProperty("contactInfo", embeddedContactInfo);

Retrieve the Embedded Entity: 

Entity employee = datastore.get(employeeKey);
EmbeddedEntity embeddedContactInfo = (EmbeddedEntity) employee.getProperty("contactInfo");

On the above, the ContactInfo is embedded to the Employee. Here are current documentations about the EmbeddedEntity class and GitHub test implementations.
Reply all
Reply to author
Forward
0 new messages