My DAO class extends HibernateDAOSupport and i am doing all the CRUD operations using getHibernateTemplate().*** methods. Secondly i have my service layer on which i have put the @Transactional Attrbutes.....it looks like this
<code>private IDownloadGroupDao downloadGroupDao;
public void setDownloadGroupDao(IDownloadGroupDao downloadGroupDao) {
this.downloadGroupDao = downloadGroupDao;
}
@Transactional(propagation=Propagation.REQUIRED,re adOnly=true, rollbackFor=Throwable.class)
public DownloadGroup getDownloadGroupById(long id) throws DAOException{
try{
return downloadGroupDao.getDownloadGroupById(id);
}catch(Exception e){
String message = "Exception Occured while retriving the information for Download Group Id = "+id;
logger.log(Level.ERROR,message);
throw new DAOException(message, e);
}
}
@Transactional(propagation=Propagation.REQUIRED,re adOnly=false, rollbackFor=Throwable.class)
public DownloadGroup updateDownloadGroup(DownloadGroup downloadGroup)throws DAOException{
try{
return downloadGroupDao.updateDownloadGroup(downloadGroup );
}catch(Exception e){
String message = "Exception Occured while updating the information for Download Group Id = "+downloadGroup.getDownloadGroupId();
logger.log(Level.ERROR,message);
throw new DAOException(message, e);
}
}
</code>
Now i am writing my test case as follows:
<code>@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/com/vmware/core/sca/resources/test-spring-config-blueprint.xml"})
public class DownloadGroupServiceTest{
private IDownloadGroupService downloadGroupService;
@Resource
public void setDownloadGroupService(IDownloadGroupService downloadGroupService) {
this.downloadGroupService = downloadGroupService;
}
// @Test
public void testGetDownloadGroupById() throws DAOException{
DownloadGroup downloadGroup = downloadGroupService.getDownloadGroupById(125);
System.out.println(downloadGroup.getBaseServerURL( ));
System.out.println(downloadGroup.getDownloadHeader ());
//System.out.println(downloadGroup.getCreatedBy().ge tEmailId());
downloadGroup.setDlgFlowStatus("My New Status 123");
}</code>
This code gives me org.hibernate.LazyInitializationException: could not initialize proxy - no Session exception.
I thought that when i have described my transaction on service methods, it should start a hibernate session there itself, but its not the case.
I have attached the error log, with this post, please take a look. I can see spring loading my Service bean and also identifying the Transactional attribute.
By the way this test case works if i add @Transaction on the test class, which i am not at all able to understand. Please clarify this doubt.