我要面对这样的场景:我有三个实体(EntA、EntB和EntC),EntA和EntB都有Key< EntC>参数。此外,EntC有一个List< String>参数,它将EntA和EntB的键作为字符串保存。
为了获得任何实体的键,我首先必须持久化它们(id字段是自动生成的)。所以我要这么做:
。
我想知道是否有更好的方法来解决这个问题。另外,是否有可能在删除原始EntC实体之后,在保存新的EntC实体之前,另一个实体获得它的id?
发布于 2012-06-08 02:50:43
预先分配id:
例如,与父母一起做:
Key<YourEntity> k= dao.fact().allocateId(parentObj, YourEntity.class);
(obviously dao extends DAOBase, I think you know that from using objectify)
allocateId(java.lang.Class<T> clazz)
Allocates a single id from the allocator for the specified kind.
allocateId(java.lang.Object parentKeyOrEntity, java.lang.Class<T> clazz)
Allocates a single id from the allocator for the specified kind.http://objectify-appengine.googlecode.com/svn/trunk/javadoc/com/googlecode/objectify/ObjectifyFactory.html
https://stackoverflow.com/questions/10942377
复制相似问题