I am using version 2.0.3.
I have a one-to-many association between a Vehicle and its Timetables using the following mapping
<class name="org.fsl.lmis.licensing.businessobjects.Vehicle"
table="VEHICLE"
schema="LICENSING">
<id name="vehicleNo" column="VEHICLE_NO" type="integer">
<generator class="assigned"/>
</id>
<set name="timetables"
table="TIME_TABLE_HDR"
schema="LICENSING"
lazy="false"
inverse="true">
<key column="VEHICLE_NO"/>
<one-to-many class="org.fsl.lmis.licensing.businessobjects.Timetable" />
</set>
<many-to-one name="lastLicenceApplication"
column="LAST_APPL_NO" class="org.fsl.lmis.licensing.businessobjects.LicenceApplication"/>
</class>
<class name="org.fsl.lmis.licensing.businessobjects.Timetable"
schema ="LICENSING"
table="TIME_TABLE_HDR">
<id name="id" column="TIME_TABLE_ID" type="long">
<generator class="sequence">
<param name="sequence">LICENSING.seq_time_table</param>
</generator>
</id>
<set name="timetablePoints"
schema="LICENSING"
lazy="false"
cascade="all"
inverse="true">
<key column="TIME_TABLE_ID"/>
<one-to-many class="org.fsl.lmis.licensing.businessobjects.TimetablePoint" />
</set>
<many-to-one name="vehicle" column="VEHICLE_NO" class="org.fsl.lmis.licensing.businessobjects.Vehicle"/>
<many-to-one name="application" column="APPL_NO" class="org.fsl.lmis.licensing.businessobjects.LicenceApplication" cascade="all"/>
</class>
As the mapping shows this relationship is non-lazy. The Vehicle class is itself mapped ad part of a set on a LicenceApplication
<set
name="vehicles"
inverse="true"
lazy="false"
cascade="all">
<key column="LAST_APPL_NO"/>
<one-to-many class="org.fsl.lmis.licensing.businessobjects.Vehicle" />
</set>
When the following query is issued
Code:
"select licApp from LicenceApplication licApp left outer join fetch licApp.routePoints " + " join licApp.customer where licApp.applicationNumber = ? ", new Long(criteria.getApplicationNumber()),
Hibernate.LONG);
the code works as long as a Timetable is present. Where there is no timetable in the database I am getting a NullPointerException in Hibernate code
//----------------------------------------------------------------------------
R
java.lang.NullPointerException
net.sf.hibernate.impl.SessionImpl.getLoadingCollection(SessionImpl.java:2759)
net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:58)
at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:170)
net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1971)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:588)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2844)
at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128)
at net.sf.hibernate.type.PersistentCollectionType.getCollection(PersistentCollectionType.java:70)
at net.sf.hibernate.type.PersistentCollectionType.resolveIdentifier(PersistentCollectionType.java:170)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:1971)
at net.sf.hibernate.loader.Loader.doFind(Loader.java:196)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:588)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:102)
at net.sf.hibernate.impl.SessionImpl.initialize(SessionImpl.java:2844)
at net.sf.hibernate.collection.PersistentCollection.getInitialValue(PersistentCollection.java:128)