I though I understood lazy/eager loading, but obviously I don't:
I have a service that is marked @Transactional, yet when I try to manipulate the list I get (accessing its objects), I get "org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: tld.myproduct.data.entities.CategoryType.translatableText, no session or session was closed". Any suggestions to why I cannot access my under-objects?
UPDATE: The exception happens at the line "type.getTranslatableText().size()"
Cheers
Nik
// The service
@Service("categoryTypeService")
@Transactional("transactionManager")
public class CategoryTypeServiceImpl extends AbstractCRUDServiceImpl<CategoryType, Integer> implements CategoryTypeService {
@SuppressWarnings("unchecked")
@Override
public List<CategoryType> getAll() {
List<CategoryType> list = DAO.getSession().createCriteria(CategoryType.class).list();
for(CategoryType type : list)
type.getTranslatableText().size(); // Access TranslatableText to demonstrate problem
return list;
}
}
// The entity
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
@Configurable(preConstruction=true)
public class CategoryType {
@Id
@Column(nullable = false)
private Integer id;
@Column(length = 50, nullable = true)
private String description;
@Column(name = "TranslatableDescriptionId", nullable = false)
private Integer TranslatableDescriptionId;
@OneToMany(fetch=FetchType.LAZY)
@JoinColumn(name = "Id", referencedColumnName="TranslatableDescriptionId", insertable=false, updatable=false)
private Set<TranslatableText> translatableText;
/** getters and setters **/
}