Hi, I am having an odd problem where I cannot lazy initialize a collection.
In the DAO have the following method:
Code:
public AirlineImpl readAirline(String pCode, Set<String> pReadOpts) throws NotFoundException {
AirlineImpl airline;
try {
airline = (AirlineImpl) em.createQuery("Select a From AirlineImpl a WHERE a.code = " +
"'" + pCode + "'").getSingleResult();
// Now lazy load requested objects
if (pReadOpts.contains(AirlinePersistenceConstants.AirlineContact)) {
Hibernate.initialize(airline.getAirlineContact()); // Lazy load contact
}
if (pReadOpts.contains(AirlinePersistenceConstants.AirlineUnitsOfMeasure)) {
Hibernate.initialize(airline.getAirlineUnitsOfMeasure()); // Lazy load contact
}
if (pReadOpts.contains(AirlinePersistenceConstants.AirlineLoadCodes)) {
Hibernate.initialize(airline.getAirlineLoadInformationCodes());
Set<AirlineLoadInformationCode> d = airline.getAirlineLoadInformationCodes(); // Lazy load contact
}
em.flush();
} catch (NoResultException e) {
throw new NotFoundException();
}
return airline;
}
The code in question is:
Code:
if (pReadOpts.contains(AirlinePersistenceConstants.AirlineLoadCodes)) {
Hibernate.initialize(airline.getAirlineLoadInformationCodes());
Set<AirlineLoadInformationCode> d = airline.getAirlineLoadInformationCodes(); // Lazy load contact
}
No matter what I do, the object type both before and after this code is PersistentSet. How do I get this object initalized correctly? It should be a HashSet.
Code:
<set name="AirlineLoadInformationCodes" lazy="true" cascade="save-update,lock" inverse="true">
<key column="airlineid" not-null="true"/>
<one-to-many class="com.sita.wab.entities.AirlineLoadInformationCodeImpl"/>
</set>
I'm sure it is a simple problem.
Thanks in advance!
Paul