EclipseLink JPA Object不是已知的实体类型

时间:2012-06-09 12:11:45

标签: java mysql jpa eclipselink

我对eclipseLink和我想要坚持的对象有一个奇怪的问题。我有一个Object(KeypointListImpl),它在List中存储另一个对象KeypointImpl。保持keypointImpl对象的效果很好但是如果我尝试持久化keypointListImpl对象,我会得到一个java.lang.IllegalArgumentException,它表示对象keypointImpl不是已知的实体类型。

这是KeypointImpl代码:

@Entity
@Table(name="Keypoints")
public class KeypointImpl implements Keypoint {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @Enumerated(EnumType.STRING)
    private DetectorType keypointType;
    private float x;
    private float y;
    private float size;
    private float angle;
    private float response;
    private int octave;
    private int classId;
    ...
}

这是KeypointListImpl代码:

@Entity
@Table(name="KeypointLists")
public class KeypointListImpl implements KeypointList {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    @OneToOne(cascade={CascadeType.ALL}, targetEntity=KeypointImpl.class)
    private List<Keypoint> keypoints;
    ...
}

以下是电源内容:

    Keypoint kp1 = new KeypointImpl(DetectorType.FAST, 5, 5, 10, 90, 2, 3, 0);
    Keypoint kp2 = new KeypointImpl(DetectorType.FAST, 6, 6, 3, 45, 1, 2, 1);

    em.persist(kp1);
    em.persist(kp2);

    List<Keypoint> keypoints = new ArrayList<Keypoint>();
    keypoints.add(kp1);
    keypoints.add(kp2);

    KeypointList keypointlist = new KeypointListImpl();
    keypointlist.setKeypointList(keypoints);

    em.persist(keypointlist);

构造的表看起来很好。我得到一个KeypointsLists(ID,KEYPOINTS_ID)和一个Keypoints(...,...)表。

有人能指出我的错误吗?! : - )

请求persistence.xml以及

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">

    <persistence-unit name="AudiModelRecognition" transaction-type="RESOURCE_LOCAL">

        <class>amr.model.KeypointImpl</class>
        <class>amr.model.KeypointListImpl</class>

        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/amr" />
            <property name="javax.persistence.jdbc.user" value="arm" />
            <property name="javax.persistence.jdbc.password" value="..." /> 

            <!-- EclipseLink should create the database schema automatically -->
            <property name="eclipselink.ddl-generation" value="create-tables" />
            <property name="eclipselink.ddl-generation.output-mode" value="database" />
        </properties>

    </persistence-unit>
</persistence>

1 个答案:

答案 0 :(得分:4)

我会把我的评论写成答案:列表上的@OneToOne看起来不对。使用@OneToMany。