SQL JPA - Multiple columns as primary key

前端 未结 5 1388
猫巷女王i
猫巷女王i 2020-12-23 09:51

If i want severeal Column to make up an ID.

SQL example :

CONSTRAINT [PK_NAME] PRIMARY KEY ([Column1],[Column2],[Column3])

How can

5条回答
  •  醉话见心
    2020-12-23 10:29

    If all fields in the class are part of primary key, then solution would be pretty simple (extending solution provided by @raul-cuth):

    @Entity
    @IdClass(EntityExample.class)
    public class EntityExample implements Serializable {
    
        @Id
        private int column1;
    
        @Id
        private int column2;
    
        @Id
        private int column3;
    }
    

提交回复
热议问题