IllegalArgumentException: expecting IdClass mapping

前端 未结 3 724
悲&欢浪女
悲&欢浪女 2020-12-10 14:44

During deploying my app I occurs on that exception. I have a lot of class in my app and I dont know where I must to place @IdClass and what does this exception

3条回答
  •  没有蜡笔的小新
    2020-12-10 15:25

    @IdClass annotation is used to define the Class that contains the id. i.e. This is generally used in case defining a compound key. i.e. a key composite of more than one attribute. If that is the case, than this is how we do. take a look at following example.. we define a class as IdClass and use @Id's to define varrious Ids for thisIdClass`.

    Example :

    @Entity
    @IdClass(AssignedRoleId.class)
    public class AssignedRole
    {
      @Id
      @ManyToOne
      private User userId;
    
      @Id
      @ManyToOne  
      private Role roleId;
    
      private Date dateAssigned;
    }
    

    Hope this helps.

提交回复
热议问题