简体   繁体   English

“ DataNucleus Enhancer已完成,但有错误”

[英]“DataNucleus Enhancer completed with an error”

Am trying to create a model class to store an Entity in Google App Engine using Eclipse.But when i save my work i get the error message: 我正在尝试创建模型类以使用Eclipse将实体存储在Google App Engine中。但是当我保存工作时,出现错误消息:

org.datanucleus.metadata.MetaDataManager initialiseFileMetaDataForUse. org.datanucleus.metadata.MetaDataManager initialiseFileMetaDataForUse。
SEVERE: Class "com.packagename.classname" has been specified with an object-id class javax.jdo.identity.StringIdentity yet no fields have been identified as primary key fields. 严重:已使用对象标识类javax.jdo.identity.StringIdentity指定“ com.packagename.classname”类,但尚未将任何字段标识为主键字段。 Please notate using the "primary-key" tag against the fields that should be considered part of the primary key. 请在应视为主键一部分的字段上注明“主键”标记。

If my understanding of JPA is correct, i do not need a primary-key for an entity since i already have a @Id tag.Here is my class. 如果我对JPA的理解是正确的,则因为我已经有@Id标记,所以我不需要实体的primary-key ,这是我的课程。

@Entity
  public class MyCLassName {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private static String userName;

private static String location;
private static Date dateOfBirth;
private static int age;
private static String gender;
private static String teamName;
private static int weight;





//Constructor with arguments
public MyClassName(String userName, String location, String gender, int age, Date DOB, int weight) {
    MyClassName.userName = userName;
    MyClassName.location = location;
    MyClassName.gender = gender;
    MyClassName.age=age;
    MyClassName = DOB;
    MyClassName.weight = weight;

}
//setter methods
public static void setUserName(String userName) {
    MyClassName.userName = userName;
}

public static void setLocation(String location) {
    MyClassName.location = location;
}

public static void setGender(String gender) {
    MyClassName.gender = gender;
}

public static void setAge(int age) {
    MyClassName.age = age;
}

public static void setDateOfBirth(Date dateOfBirth) {
    MyClassName.dateOfBirth = dateOfBirth;
}

public static void setWeight(int weight) {
     MyClassName.weight = weight;
}

//getter methods
public static String getUserName() {
    return userName;
}

public static int getWeight() {
    return weight;
}

public static String getLocation() {
    return location;
}

public static String getGender() {
    return gender;
}

public static String getTeamName() {
    return teamName;
}

public static Date getDateOfBirth() {
    return dateOfBirth;
}

public static int getAge() {
    return age;
}

    }

What exactly am i doing wrong here? 我到底在做什么错?

Your understanding of JPA is partially correct. 您对JPA的理解部分正确。 You do not need to assign the primary key because you have used the @Id and @GeneratedValue annotation. 您不需要分配主键,因为您已经使用了@Id和@GeneratedValue批注。 The JPA implementation will automatically generate the primary key value as a long integer. JPA实现将自动将主键值生成为长整数。 However it still needs a field in which to store this ID value. 但是,它仍然需要一个用于存储此ID值的字段。 It is trying to do that in userName. 它正在尝试在userName中执行此操作。 See Java Tutorial ID Generation Type: IDENTITY for example. 例如,请参阅Java教程ID生成类型:IDENTITY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM