I am using datanucleus with MySQL for my project. When I try to persist an object I am receiving the exception
Incorrect table definition; there can be only one auto column and it must be defined as a key error
My object design is as follows
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
}
I am not using more than one ID in any of the class. Please help me.
The id in the currency was creating the problem. I added the @primarykey annotation and it started working. Thank you all for your replies..