Hans Sperker
Hans Sperker

Reputation: 1347

EclipseLink JPA Object is not a known entity type

I have a strange problem with eclipseLink and an object which I want to persist. I have one Object (KeypointListImpl) that stores another object KeypointImpl in a List. Persisting a keypointImpl objects works great but if I try to persist a keypointListImpl object I get an java.lang.IllegalArgumentException that says the object keypointImpl isn't a known entity type.

Here is the KeypointImpl Code:

@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;
    ...
}

Here is the KeypointListImpl Code:

@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;
    ...
}

Here is the mains content:

    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);

The tables that are constructed look fine. I get a KeypointsLists(ID, KEYPOINTS_ID) and a Keypoints(..., ...) table.

Can anyone point me to my error please?! :-)

As requested the persistence.xml as well

<?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>

Upvotes: 2

Views: 10303

Answers (1)

popfalushi
popfalushi

Reputation: 1362

Than I'll write my comment as an answer: @OneToOne on List looks wrong. Use @OneToMany.

Upvotes: 4

Related Questions