Home Find an entity which use a class Id
Reply: 0

Find an entity which use a class Id

user892
1#
user892 Published in July 16, 2018, 6:14 pm

To find an object from entity with primary key we use em.find(Person.class, <Id>).

I'm using JPA EclipseLink and I have a Person entity wich has a composite primary key(@classId),

the Person entity:

@Entity
    @IdClass(PersonId.class)
    public class Person {

@Id
private int id;

@Id
private String name;

public String getName() {
    return name;
}

// getters & setters
}

and the PersonID:

public class PersonId implements Serializable {

private static final long idVersionUID = 343L;

private int id;
private String name;

// must have a default construcot
public PersonId() {

}

public PersonId(int id, String name) {
    this.id = id;
    this.name = name;
}

//getters & setters
//hachCode & equals
}

How to use em.find to get a Person object?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.394274 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO