Skip to content
Advertisement

Is there a way to use @OneToMany and @ManyToMany to handle polymorphism in hibernate

I am working on app that uses microservices architecture, i have project A which has this entity User with this code

@JoinTable(
    name = "USER_AUTHORITY", 
    joinColumns = { @JoinColumn(
        name = "USER_ID",
        referencedColumnName = "id") },
    inverseJoinColumns = { @JoinColumn(
        name = "AUTHORITY_ID", 
        referencedColumnName = "id") })
private List<Authority> authorities;

and another entity Authority

@Entity
@Table(name = "AUTHORITY")
public class Authority {
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE,
 generator = "authority_seq")
@SequenceGenerator(name = "authority_seq",
 sequenceName = 
  "authority_seq", allocationSize = 1)
private Long id;

  @ManyToMany(mappedBy = "authorities", fetch = FetchType.LAZY)
  private List<User> users;
}

and i have project B which has entity AAA with this code:

@Entity
public class subUser extends User

so when i run the the project B I get the following error:

org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.A.model.User.authorities[com.A.model.Authority

Advertisement

Answer

I get the solution from here the link may be it help someone

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement