Hi,
I've been using Hibernate for a while but every now and then there is something I just don't understand - like this:
This is the mapped class (importang part separated):
Code:
<hibernate-mapping default-lazy="false" default-cascade="none" default-access="property" auto-import="true">
<class name="de.infrage.server.model.Ressource" table="ressources" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<id name="id" column="id" type="java.lang.Integer" unsaved-value="null">
<generator class="native">
</generator>
</id>
<property name="mimetype" type="java.lang.String" update="true" insert="true" column="mimetype" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="comment" type="java.lang.String" update="true" insert="true" column="comment" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="size" type="long" update="true" insert="true" column="size" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<many-to-one name="ressourceFile" class="de.infrage.server.model.RessourceFile" cascade="all" outer-join="auto" update="true" insert="true" column="file_id" unique="false" optimistic-lock="true" not-found="exception" embed-xml="true" />
-------------------------------------------------------------
<set name="tags" table="ressources_tags" lazy="false" cascade="none" sort="unsorted" inverse="false" mutable="true" optimistic-lock="true" embed-xml="true">
<key column="ressource_id" on-delete="noaction" />
<many-to-many class="de.infrage.server.model.Tag" column="tag_id" outer-join="auto" embed-xml="true" not-found="exception" unique="false" />
</set>
-------------------------------------------------------------
<joined-subclass name="de.infrage.server.model.NewspaperArticle" table="newspaper_articles" dynamic-update="false" dynamic-insert="false" select-before-update="false">
<key column="ressource_id" on-delete="noaction" />
<property name="newspaper" type="java.lang.String" update="true" insert="true" column="newspaper" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="date" type="java.util.Date" update="true" insert="true" column="date" unique="false" optimistic-lock="true" lazy="false" generated="never" />
<property name="issue" type="java.lang.Integer" update="true" insert="true" column="issue" unique="false" optimistic-lock="true" lazy="false" generated="never" />
</joined-subclass>
</class>
</hibernate-mapping>
What troubles me is the
set/many-to-many relation. I set it to lazy="false", but loading a ressource, closing the session and accessing "tags" aftwerwards gives me...
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
... as I would expect in the case of lazy="false".
I tried a
join fetch ("from Ressource as res left outer join fetch res.tags") instead, but then I get each Ressource as often as there are Tags in it - like a "real" SQL outer join.
Help much appreciated,
meikel