Hibernate version: 2.1.6, 9.8.2004
Mapping documents:
Code:
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class name="com.isthmus.electronic.payments.hibernate.ProviderPerson" table="ProviderPerson">
<id name="idproviderPerson" type="java.lang.String" column="IdProviderPerson" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<property name="name" type="java.lang.String" column="name" not-null="true" length="18"/>
<property name="idnumber" type="java.lang.String" column="IdNumber" not-null="true" length="18"/>
<!-- Associations -->
<!-- bi-directional one-to-many association to ProviderBill -->
<set name="providerBills" lazy="true" inverse="true" cascade="none">
<key>
<column name="IdProviderPerson"/>
</key>
<one-to-many class="com.isthmus.electronic.payments.hibernate.ProviderBill"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
ProviderPerson providerPerson = (ProviderPerson) session.load(ProviderPerson.class, "2c9280e50043c3c8010043c3cb0d0001");
Full stack trace of any exception that occurs:
This is the exception I'm trying to avoid on the client when an object with no collection loaded is retrieved:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.toString(Set.java:217)
at java.lang.String.valueOf(String.java:2466)
at java.lang.StringBuffer.append(StringBuffer.java:387)
at EjbClient.main(EjbClient.java:41)
at java.lang.reflect.Method.invoke(Native Method)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Exception in thread "P=516386:O=0:CT"
Name and version of the database you are using:
Microsoft SQL Server 2000
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A
Hello, I'm using a stateless session bean to retrieve the PersonProvider entity (that it's related one-to-many with the ProviderBill entity), my idea was to avoid using the DTO pattern by simply returning the POJO retrieved by Hibernate on a simple load() operation.
I was pretty excited with the idea of having lazy collections because I wouldn't want to load a huge graph every time I want to read an entity (specially if there are cases when I'm not going to need the FK values!). My question is if there is any way to indicate dinamically (on runtime) to the session that I'm going to do a lazy load or not (not by specifying it in the mapping file), because sometimes I'd like to use a full collection load and sometimes I won't need the collection at all. I don't want an open session on my client application (swing).
Any help will be very appreciated!