What are the advantages/disadvantages of mapping collections as value types vs. entity types? In the past I've nearly always mapped collections as entity types because, for better or worse, that was the habit I was in. I think part of my thinking was that collections mapped as value types weren't queryable - but I believe that is no longer the case since 2.1 (please correct me if I'm wrong). The only times I mapped collections as value types were many-to-many associations where the association table contained no other columns.
Lately, I've been experimenting with mapping collections as values including complex mapped many-to-many composite-element mappings. To me, it seems simpler than the equivalent entity mapping approach. Especially for many-to-many mappings where the association table has no other columns because I don't end up with this artificial entity that I have to navigate through to get to the "real" entity that makes up the collection. And it's also simpler from the respect of not having to mess with cascade and inverse=true settings.
From the documentation and forum archives, I've gathered that the drawbacks for mapping collections as value types are:
- cannot contain collections (no nested collections)
- for a many-to-many composite element, a 2 column primary key required on the table for the composite-element (but if the columns that make up the PK are themselves surrogate keys, is this really a drawback?)
- Interceptors don't see value type collections items since they are not entities.
- anything else?
Also, from the documentation, it seems that the recommended approach is to map collections as entities. (See "Don't use exotic association mappings" in
http://www.hibernate.org/hib_docs/reference/en/html/best-practices.html)
Is the choice purely a personal preference (as long as one of the above disadvantages to value mapped collections doesn't apply)? Is one technique preferred over the other due to the sql generated or other factors?
Any insight is greatly appreciated - even a RTFM reply :)
Regards,
-Jay