<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb" -->

---
title: Solving org.hibernate.AnnotationException: Illegal...
description: When using Hibernate's @OneToMany, @ManyToMany, or @ElementCollection annotations, the mapped field must be declared as a collection interface (List, Set, or...
canonical: https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Solving org.hibernate.AnnotationException: Illegal Attempt to Map a Non Collection | daily.dev
og:description: When using Hibernate's @OneToMany, @ManyToMany, or @ElementCollection annotations, the mapped field must be declared as a collection interface (List, Set, or...
og:url: https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb
og:image: https://api.daily.dev/og/posts/LGaLDi4jB.png
og:image:alt: Solving org.hibernate.AnnotationException: Illegal Attempt to Map a Non Collection
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Solving org.hibernate.AnnotationException: Illegal Attempt to Map a Non Collection

**[Baeldung](https://daily.dev/sources/baeldung)** · 5 min read · 1 upvotes · 0 comments

## Summary

When using Hibernate's @OneToMany, @ManyToMany, or @ElementCollection annotations, the mapped field must be declared as a collection interface (List, Set, or Map), not a concrete class like ArrayList. Using a concrete type causes Hibernate to throw an AnnotationException at startup because it cannot create its proxy implementation. The fix is to change the field declaration to the appropriate interface while keeping the concrete class as the initializer. A second related cause is placing a collection annotation on a single-valued field — in that case, the correct fix is to use @ManyToOne or @OneToOne to match the actual cardinality of the relationship.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://feeds.feedblitz.com/~/960891746/0/baeldung~Solving-orghibernateAnnotationException-Illegal-Attempt-to-Map-a-Non-Collection>

## Questions this post answers

### Why does Hibernate throw AnnotationException illegal attempt to map a non collection as OneToMany?

This happens when a field annotated with @OneToMany, @ManyToMany, or @ElementCollection is declared using a concrete class like ArrayList instead of a collection interface such as List, Set, or Map. Hibernate needs the field type to be an interface so it can replace the value with its own proxy implementation for lazy loading and dirty checking; it fails fast at startup if it cannot.

_Debugging Hibernate mapping exceptions gets faster with concrete fixes surfaced on daily.dev._

### How do I fix Hibernate AnnotationException when a OneToMany field is a single reference instead of a collection?

Switching to a collection interface will not help in this case, because the relationship itself is modeled incorrectly. When a field like Post holds a single value rather than a collection, replace @OneToMany with @ManyToOne (or @OneToOne for one-to-one associations) so the annotation matches the actual cardinality of the relationship.

_Getting entity relationships right the first time is easier with practical fixes like this on daily.dev._

### Can I declare a Hibernate collection field as ArrayList and still initialize it with new ArrayList<>()?

No, the declared field type must be a collection interface like List, but initializing the field's value with new ArrayList<>() is fine and expected. Only the compile-time declared type needs to be an interface; Hibernate swaps in its own implementation once the entity becomes managed, so the ArrayList initialization itself never causes the AnnotationException.

_Getting JPA entity mapping conventions right matters for anyone tracking Hibernate best practices on daily.dev._

## Similar posts on daily.dev

- [How to Define Custom Enum Mappings with @EnumeratedValue](https://daily.dev/posts/how-to-define-custom-enum-mappings-with-enumeratedvalue-agl0xko18) · Jakarta EE · 0 upvotes · 0 comments
- [The @Find Annotation in Hibernate](https://daily.dev/posts/the-find-annotation-in-hibernate-fxuii43ae) · Baeldung · 3 upvotes · 0 comments
- [In Relation To](https://daily.dev/posts/in-relation-to-naofi9gan) · Hibernate Blog · 0 upvotes · 0 comments
- [Hibernate Turned 11,000 Records Into 50 Million Rows](https://daily.dev/posts/hibernate-turned-11-000-records-into-50-million-rows-gsexbezep) · Code Like A Girl · 38 upvotes · 1 comments

---

Tags: [#java](https://daily.dev/tags/java)

[View this post on daily.dev](https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Solving org.hibernate.AnnotationException: Illegal Attempt to Map a Non Collection","url":"https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb"},"datePublished":"2026-07-19T01:57:43.077Z","dateModified":"2026-09-13T18:40:11.450Z","description":"When using Hibernate's @OneToMany, @ManyToMany, or @ElementCollection annotations, the mapped field must be declared as a collection interface (List, Set, or...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f3936b726a3720f3151636207d7cddad?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f3936b726a3720f3151636207d7cddad?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Baeldung","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Baeldung","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/52cccfb454d946c4b7dfa5e816f9e576","url":"https://daily.dev/sources/baeldung"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"java","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Baeldung","item":"https://daily.dev/sources/baeldung"},{"@type":"ListItem","position":3,"name":"Solving org.hibernate.AnnotationException: Illegal Attempt to Map a Non Collection"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/solving-org-hibernate-annotationexception-illegal-attempt-to-map-a-non-collection-lgaldi4jb#faq","mainEntity":[{"@type":"Question","name":"Why does Hibernate throw AnnotationException illegal attempt to map a non collection as OneToMany?","acceptedAnswer":{"@type":"Answer","text":"This happens when a field annotated with @OneToMany, @ManyToMany, or @ElementCollection is declared using a concrete class like ArrayList instead of a collection interface such as List, Set, or Map. Hibernate needs the field type to be an interface so it can replace the value with its own proxy implementation for lazy loading and dirty checking; it fails fast at startup if it cannot. Debugging Hibernate mapping exceptions gets faster with concrete fixes surfaced on daily.dev."}},{"@type":"Question","name":"How do I fix Hibernate AnnotationException when a OneToMany field is a single reference instead of a collection?","acceptedAnswer":{"@type":"Answer","text":"Switching to a collection interface will not help in this case, because the relationship itself is modeled incorrectly. When a field like Post holds a single value rather than a collection, replace @OneToMany with @ManyToOne (or @OneToOne for one-to-one associations) so the annotation matches the actual cardinality of the relationship. Getting entity relationships right the first time is easier with practical fixes like this on daily.dev."}},{"@type":"Question","name":"Can I declare a Hibernate collection field as ArrayList and still initialize it with new ArrayList<>()?","acceptedAnswer":{"@type":"Answer","text":"No, the declared field type must be a collection interface like List, but initializing the field's value with new ArrayList<>() is fine and expected. Only the compile-time declared type needs to be an interface; Hibernate swaps in its own implementation once the entity becomes managed, so the ArrayList initialization itself never causes the AnnotationException. Getting JPA entity mapping conventions right matters for anyone tracking Hibernate best practices on daily.dev."}}]}
```

