JPA中的复合主键 [英] Composite Primary key in JPA

查看:138
本文介绍了JPA中的复合主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

EmbeddedId或IdClass批注用于表示复合主键. 我如何使用没有(EmbeddedId或IdClass)的复合主键??

The EmbeddedId or IdClass annotation is used to denote a composite primary key. How can i use composite primary key without ( EmbeddedId or IdClass ) ?

如果可以使用不带(EmbeddedId或IdClass)的复合主键,那么在复合主键的情况下,如何使用 EntityManager.find(Entity Class,Object primaryKey)方法查找实体 (多个主键)(因为没有IdClass或EmbeddedId).

If it is possible to use composite primary key without ( EmbeddedId or IdClass ) then how can i use EntityManager.find( Entity Class , Object primaryKey) method to find entity in case of composite primary key(Multiple Primarykey) (because of no IdClass or EmbeddedId) .

EclipseLink在find()操作中获取pk列表,但如果示例中定义了复合pk键-

EclipseLink take List of pk in the find() operation but if composite pk key defined in example -

    Entity Person {
           @Id 
           String username;
           @Id
           String emailId;
           @Basic
           String firstName;
           @Basic
           String lastName;
    }

    List list = new ArrayList();
    list.add(${username});  //Run time value
    list.add(${emailId});   //Run time value

然后 EnitityManager.find(list)将接受这些参数,对吗?

then EnitityManager.find(list) will take these arguments , is i am right?

如果我假设是正确的,那么EnitityManager.find()操作将如何知道List 1st参数是用户名或emailId pk值(表示复合pk字段值的序列)

If i am assuming correct then how will EnitityManager.find() operation will know that List 1st argument is username or emailId pk value (means sequence of composite pk fields value)

推荐答案

您应该能够在EclipseLink中将List与find()操作一起使用.

You should be able to use a List with the find() operation in EclipseLink.

这篇关于JPA中的复合主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆