Skip to content
Advertisement

Which collections are supported by Hibernate @ManyToMany annotation

I used @ManyToMany annotation on a Set and it worked fine.

JavaScript

When I used ArrayList instead of Set it throws exception:

org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: com.kaushik.winnersoft.data.Student.enrolledCourses

Is ArrayList not supported? Which all collection are supported by @ManyToMany annotation?

Advertisement

Answer

The supported interfaces are:

JavaScript

You get the exception because you have used a concrete implementation of one of those interfaces. Always define the @ManyToMany or @OneToMany using an interface as given above and you will be fine.

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