我正在将MySQL与datanucleus用于我的项目。当我尝试持久化对象时,我收到异常
表定义不正确;只有一个自动列和它 必须定义为关键错误
我的对象设计如下
Plan.class
public class Plan implements Serializable {
private static final long serialVersionUID = 6653821147113556490L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Column(name = "ID")
private Long id;
@Persistent(column = "NAME")
private String planName;
@Persistent(defaultFetchGroup = "true")
@Element(column = "FEATURES")
@Unowned
private Set<PlanFeature> planFeatures;
@Persistent(column = "CURRENCY_TYPE")
private String currency = "USD";
@Persistent(defaultFetchGroup = "true")
@Element(column = "CURRENCIES")
@Unowned
private Set<Currency> currencies;
@Persistent(column = "COST")
private BigDecimal cost = new BigDecimal(0);
@Persistent(column = "COST_INR")
private BigDecimal costINR = new BigDecimal(0);
@Persistent(column = "DISCOUNT")
private BigDecimal discount = new BigDecimal(0);
@Persistent(column = "TEST_TAKERS_ALLOWED")
private Integer testTakersAllowed;
// How many clients have opted for this plan
@Persistent(column = "OPTED_OWNERS")
private Long planOwners = 0L;
@Persistent(column = "PLAN_LEVEL")
private Integer level;
......//Getters and setters
}
PlanFeature.class
public class PlanFeature {
@Persistent(column = "NAME")
private String name;
@Persistent(column = "VALUE")
private String value;
//Getters and setters
}
Currency.class
public class Currency implements Serializable {
private static final long serialVersionUID = 8814737520234672816L;
@Persistent(column = "ID", valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent(column = "COUNTRY")
private String country;
@Persistent(column = "CURRENCY")
private String currency;
//Getters and setters
}
我没有在任何一个类中使用多个ID。请帮帮我。
答案 0 :(得分:0)
货币中的ID正在创建问题。我添加了@primarykey注释,它开始工作了。谢谢大家的答复..