Hi subich!
Thanks for the quick response! Well, I'm not using lazy=true for my child object. Actually, the instance that gets queried for its "isbn" in my example is transient - it hasn't been saved at all - so I believe it doesn't have to be initialized. The parent object, however, is persistent and seems to be failing to initialize properly even with an open session. The collection that throws the exception is 'isbn2book'.
My guess is that perhaps I cannot open a session from a method in a persistent object and try to access a lazily initialized collection (which is an attribute of that same object). Maybe hibernate associates some sort context info with the session, introducing this issue.
I'll paste in the mapping files now, if you need any other info I'll be glad to supply it!
Best regards!
Parent:
Code:
<hibernate-mapping>
<class
name="Biblio.implementation.BibliotecaImpl"
table="BIBLIOTECA"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="biblio_id"
type="int"
>
<generator class="native">
</generator>
</id>
<property
name="nome"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NOME"
/>
<property
name="cidade"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="CIDADE"
/>
<property
name="estado"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="ESTADO"
/>
<map
name="isbn2book"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all-delete-orphan"
>
<key
column="BIBLIO_ID"
>
</key>
<index
column="ISBN"
type="string"
/>
<one-to-many
class="Biblio.implementation.LivroImpl"
/>
</map>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-BibliotecaImpl.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Child
Code:
<hibernate-mapping>
<class
name="Biblio.implementation.LivroImpl"
table="LIVRO"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="livro_hib_id"
column="LIVRO_ID"
type="long"
>
<generator class="native">
</generator>
</id>
<array
name="autores"
inverse="false"
cascade="none"
>
<key
column="LIVRO_ID"
>
</key>
<index
column="NDX_AUTOR"
/>
<element
column="AUTOR"
type="string"
not-null="false"
unique="false"
/>
</array>
<property
name="exid"
type="int"
update="true"
insert="true"
access="property"
column="ATTRIB_ID_EXEMPLAR"
/>
<map
name="id2exemplar"
lazy="true"
sort="unsorted"
inverse="false"
cascade="all-delete-orphan"
>
<key
column="livro_hib_id"
>
</key>
<index
column="chave_exemplar"
type="string"
/>
<one-to-many
class="Biblio.implementation.ExemplarDeLivroImpl"
/>
</map>
<property
name="isbn"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="ISBN"
/>
<many-to-one
name="parent"
class="Biblio.implementation.BibliotecaImpl"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="BIB_PARENT"
/>
<property
name="titulo"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="TITULO"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-LivroImpl.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>