mercredi 27 mai 2015

EJB find method and multiple identifiers

I have the following entity bean that contains multiple @Id:

@Entity
@Table (name="meta_tables")
public class MetaTableEnt implements Serializable{

    @Id     
    @Column(name="data_ind")
    private Integer dataInd;

    @Id     
    @Column(name="sk")
    private Integer sk;

    // other columns

}

and need to implement the find method:

MetaTableEnt mte = em.find(MetaTableEnt.class, object);

I defined object as follows, however this doesn't work:

public class MetaTableKey implements Serializable {
    public int dbInd;
    public int sk;
}

MetaTableKey object = new MetaTableKey();
object.dbInd = dbInd;
object.sk = sk;

I get this error message:

Provided id of the wrong type for class bi.metadata.MetaTableEnt. Expected: class bi.metadata.MetaTableEnt, got class bi.metadata.MetaTableDao$MetaTableKey

What's wrong with this code?

Aucun commentaire:

Enregistrer un commentaire