I've been a bit aggressive in my lazyness of many to many. I think I'm gonna relax that in the next release to allow objects to be initialized when the @ManyToMany collection is touched.
Note that the spec allow such an aggressive lazy loading, so a code expecting to be portable should not rely on the object loading except if all the objects state are touched, a "fetch" keyword is used in HQL or the collection is marked as EAGER
Thanks for the reply, and for relaxing the aggressive lazy loading of many-to-many in next release. I do think that the behavior should be consistent for both one-to-many and many-to-many, aggressive or not. Would you like me to enter an entry in JIRA? If so, is this a bug or a feature request?
On a slightly different aspect, I think the spec needs to address the following:
1. in entity manager, need a way for forced initialization of all relationships of a bean, one similar to Hibernate.initialize(parent).
2. forced initialization of selected relationship. For example, entity A has a relationship with entity B as AB, and has a relationship with entity C as AC, it will be very convenient to have initialzing only relationship AB without initializing relationship AC. This is what my BeanAObject.getBeanBList().size() is intended to accomplish, and the behavior that Hibernate supports.
The "fetch join" can do both. However, the pitfall of "fetch join" is that you are required to write bean specific HQL, while the 2 items that I mentioned don't.