-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mapping collections as value types vs. entity types
PostPosted: Thu Jun 10, 2004 4:20 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 9:28 pm
Posts: 25
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.