【问题标题】:Data Nucleus-MySql Incorrect table definition; there can be only one auto column and it must be defined as a key errorData Nucleus-MySql 表定义不正确;只能有一个自动列,并且必须将其定义为关键错误
【发布时间】:2015-10-15 07:14:12
【问题描述】:

我在我的项目中使用带有 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。请帮帮我。

【问题讨论】:

  • 如果你要引用一些异常消息然后发布异常和堆栈跟踪,然后人们可以看到异常来自哪里......也许你的数据库?

标签: java mysql jdo datanucleus


【解决方案1】:

货币中的 id 造成了问题。我添加了 @primarykey 注释并开始工作。谢谢大家的回复。。

【讨论】:

    猜你喜欢
    • 2015-04-05
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 2020-01-01
    • 2013-12-17
    • 2021-07-21
    • 1970-01-01
    相关资源
    最近更新 更多