0

I have an Entity

@Entity
public class EntityA{
    @Id
    @GeneratedValue
    private Long id;
    //other columns
    -------
}

I am trying to create a child Entity without primary key

@Entity
public class EntityB{
    @ManyToOne
    private EntityA entityA;
    //other columns
    -------
}

But this is throwing error for primary key for EntityB.

Can anyone help here to make this relationship without primary key in child entity.

Mohd. Samar
  • 356
  • 1
  • 4
  • 11
  • No can do. Every entity needs a primary key. – K.Nicholas Apr 20 '21 at 15:34
  • If `EntityB` does not have an identity, then by definition it is not an entity. Perhaps `@ElementCollection` is what you want – crizzis Apr 20 '21 at 16:49
  • I think crizzis is right. Here's more info that may help you decide.... https://stackoverflow.com/questions/8969059/difference-between-onetomany-and-elementcollection/8969169 – Atmas Apr 21 '21 at 03:13

0 Answers0