@Documented @Target(value=FIELD) @Retention(value=RUNTIME) public @interface Referential
Referential is a marker annotation to represent the annotated field
is referential property (References the "Master" entity as read-only). Like
this:
@Entitypublic class Entity7 {@KeyString id; int i;@ReferentialEntity1 entity1; } ... Entity1 entity1 = new Entity1(); entity1.id = "Reference1"; entity1.i = 1; Entity7 entity71 = new Entity7(); entity71.id = "Key71"; entity71.i = 71; entity71.entity1 = entity1; Entity7 entity72 = new Entity7(); entity72.id = "Key72"; entity72.i = 72; entity72.entity1 = entity1; Session session = new AppEngineDatastoreSession(); Transaction transaction = session.beginTransaction(); try { session.put(entity1); session.put(entity71); session.put(entity72); transaction.commit(); } catch (Exception e) { transaction.rollback(); throw e; } transaction = session.beginTransaction(); try { entity1 = session.get(Entity1.class, "Reference1"); entity1.i = 11; // from 1 to 11. session.update(entity1); transaction.commit(); } catch (Exception e) { transaction.commit(); throw e; } finally { session.close(); } session = new AppEngineDatastoreSession(); entity71 = session.get(Entity7.class, "Key71"); entity72 = session.get(Entity7.class, "Key72"); assertThat(entity71.entity1.i, is(11)); assertThat(entity72.entity1.i, is(11));
Copyright © 2009-2014 Eiichiro Uchiumi. All Rights Reserved.