Java 在GAE-Entity中持久化数据不能具有长主键且不能是子对象
在我们的谷歌应用引擎项目中,我们很难持久保存数据,我们有“客户”、“预订”和“房间”类 我们的目标是映射这些之间的关系,从客户到预订的一对多关系以及从房间到同一预订的一对多关系 我们得到的例外是: no.hib.mod250.asm2.model.Reservation.id的元数据错误:不能具有java.lang.Long主键,并且不能是子对象(拥有字段为no.hib.mod250.asm2.model.Customer.res) 我们的守则如下: Customer.javaJava 在GAE-Entity中持久化数据不能具有长主键且不能是子对象,java,google-app-engine,jakarta-ee,entity-relationship,jdo,Java,Google App Engine,Jakarta Ee,Entity Relationship,Jdo,在我们的谷歌应用引擎项目中,我们很难持久保存数据,我们有“客户”、“预订”和“房间”类 我们的目标是映射这些之间的关系,从客户到预订的一对多关系以及从房间到同一预订的一对多关系 我们得到的例外是: no.hib.mod250.asm2.model.Reservation.id的元数据错误:不能具有java.lang.Long主键,并且不能是子对象(拥有字段为no.hib.mod250.asm2.model.Customer.res) 我们的守则如下: Customer.java 如消息所示,如果
如消息所示,如果您的实体是子实体,则不能使用与主键一样长的键,在本例中是这样。相反,使用密钥或编码字符串作为主键-有关详细信息,请参阅 你可能也应该仔细阅读
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Customer implements Serializable {
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Long id;
(...)
//an customer has one or more reservations.
@Persistent(mappedBy="customer")
private List <Reservation> res;
(...)
}
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Room implements Serializable {
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Long id;
(...)
//a room has one or more reservations
@Persistent(mappedBy="room")
private List<Reservation> res;
@Persistent
private Hotel hotel;
(...)
}
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Reservation implements Serializable {
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
private Long id;
(...)
@Persistent
private Room room;
@Persistent
private Customer customer;
(...)
}