@Id and ID/Name

98 views
Skip to first unread message

Ilya

unread,
Apr 11, 2013, 4:01:53 PM4/11/13
to twig-p...@googlegroups.com
Is there a reason why some of my entities have both the ID/Name column and the id column in the datastore?

My models all look the same in that they have @entity and then @Id Long id

The objects that have id as a column, the value is blank, but when i call the getrer for id, i get the expected ID/Name value. Any issues here?

Thanks!

John Patterson

unread,
Apr 12, 2013, 1:55:37 AM4/12/13
to twig-p...@googlegroups.com
Perhaps the @Id field was added after some values had already been stored.  Or an @Id annotation from an incorrect package was used previously.  Basically, I'm fairly certain @Id works as expected and as the unit tests show it to work.  No Entity property should be created.


--
You received this message because you are subscribed to the Google Groups "twig-persist" group.
To unsubscribe from this group and stop receiving emails from it, send an email to twig-persist...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ilya Elkind

unread,
Apr 12, 2013, 9:37:04 AM4/12/13
to twig-p...@googlegroups.com
I have confirmed that both classes use the com.google.code.twig.annotation.Id package.

For the class that has the id column as well here is the code to persist a new object.

new Member(firstname, lastname, google, facebook, email, true, getupdates, null);
ds.store(member);

For the class that does not have the id column.
new League(description, name, c, null, null, true, Boolean.valueOf(searchable), Boolean.valueOf(sendUpdateOnActivity));
ds.store(league);

Seems similar to me. Neither of those constructors includes the id value.

The only difference I notice is that I create my Member first by intiializing it by setting Member member = null; while the other class I just create the object with the full constructor.
Could that be it?

Also is it best practice to include @Entity or not?

Thanks





--
You received this message because you are subscribed to a topic in the Google Groups "twig-persist" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/twig-persist/ydzn6zXksCk/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to twig-persist...@googlegroups.com.

Georgi Georgiev

unread,
May 27, 2013, 8:37:39 AM5/27/13
to twig-p...@googlegroups.com
Hi, 

I use last version from repo and have the same problem. To make sure that the problem is from twig I wrote a test.

public static class HasLongKey {

   @Id Long keyField;

}

@Test
public void shouldNotStorePropertyForId() throws Exception {

ObjectDatastore datastore = new AnnotationObjectDatastore();

HasLongKey hasNullKey = new HasLongKey();
datastore.store(hasNullKey);

Entity entity = DatastoreServiceFactory.getDatastoreService().get(KeyFactory.createKey("HasLongKey", 1l));

Map<String, Object> properties = entity.getProperties();

assertFalse("Property 'keyField' should not be stored", properties.keySet().contains("keyField"));

}


I did an investigation of which assume that problem occur in class FieldTranslator in method encode(...) when given property is with value null and by default index is true.

I suggest when value is null and property index is true then use translatores (row 290 in classFieldTranslator)

else if (indexed(field))
{
  // only store null if it is indexed
  PropertyTranslator translator = encoder(field, instance); 
  encoded = translator.encode(value, childPath, indexed(field));
  if (encoded == null) {
    PropertySets.singletonPropertySet(childPath, null, true);
Reply all
Reply to author
Forward
0 new messages