【发布时间】:2013-12-14 06:31:18
【问题描述】:
我有以下Entity:
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "DCOL", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("Alias")
public class Alias
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key key;
@Basic
private UUID from;
@Basic
private UUID to;
@Extension(vendorName="datanucleus", key="gae.unindexed", value="true")
private Date createdOn;
public Alias() { /* intentionally blank */ }
public Alias(@Nonnull final UUID from, @Nonnull final UUID to)
{
this.key = KeyFactory.createKey(Alias.class.getSimpleName(), from.toString());
this.from = from;
this.to = to;
this.createdOn = new Date();
}
}
这是持久化它的代码:
final EntityManager em = EMF.TRANSACTIONS_OPTIONAL.createEntityManager();
try
{
final Alias a = new Alias(from, to);
em.persist(a);
}
finally
{
em.close();
}
目前需要6 向Datastore 写入操作才能持久化此Entity。
我通过用@Extension 标记createdOn 将数字从10 减少到6,以将其从自动索引中排除。这是写操作的40% 减少!
有什么办法可以减少这么简单的事情的写入次数?
直接使用低级的Datastore API 会有什么改进吗?
【问题讨论】:
标签: google-app-engine jpa google-cloud-datastore jpa-2.0