使用eclipselink从实体创建正确ddl时出现问题

时间:2014-12-02 01:48:02

标签: jpa orm eclipselink

我有两个实体Person&具有manyToOne关系的状态

@Entity
@Table(name = "PERSON")
public class Person implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(name = "FIRST_NAME")
    private String firstName;

    @Column(name = "LAST_NAME")
    private String lastName;

    @JoinColumn(name = "STATUS_ID", referencedColumnName = "ID")
    @ManyToOne(cascade = CascadeType.ALL)
    private Status status;

    // setters & getters
}

@Entity
@Table(name = "STATUS")
public class Status implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID")
    private Integer id;

    @Column(name = "ABBREVIATION")
    private String abbreviation;

    @Column(name = "TITLE")
    private String title;

    @Basic(fetch=FetchType.LAZY)
    @OneToMany(mappedBy = "status")
    private Collection<Person> personCollection;

    // setters & getters    
}

当我尝试从这些实体自动生成db表时,我得到以下DDL:

CREATE TABLE `person` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`FIRST_NAME` VARCHAR(255) NULL DEFAULT NULL,
`LAST_NAME` VARCHAR(255) NULL DEFAULT NULL,
`NICK_NAME` VARCHAR(255) NULL DEFAULT NULL,
`STATUS_ID` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`ID`),
INDEX `FK_PERSON_STATUS_ID` (`STATUS_ID`),
CONSTRAINT `FK_PERSON_STATUS_ID` FOREIGN KEY (`STATUS_ID`) REFERENCES `status` (`ID`)
)

CREATE TABLE `status` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`ABBREVIATION` VARCHAR(255) NULL DEFAULT NULL,
`PERSONCOLLECTION` LONGBLOB NULL,
`TITLE` VARCHAR(255) NULL DEFAULT NULL,
PRIMARY KEY (`ID`)

显然有些错误,因为我的PERSONCOLLECTION LONGBLOB表中不需要status字段。 我在做映射时出错吗?

使用:Netbeans 8,Eclipselink,JPA 2.1,mysql 5.6

1 个答案:

答案 0 :(得分:1)

尝试删除@basic注释也使用&#34; List&#34;而不是&#34; Collection&#34;