I'm developing an application in Spring 3.0.5 and Hibernate 3.6.2, and currently i'm working in a JSON controller, but i have this exception and i can't understand why is happening. I've checked previously in SO and Google, but this problem is quite strange. So here is my code:
Controller
@RequestMapping(value = "/props", method = RequestMethod.GET)
public @ResponseBody
List<Property> getJsonProps(String id) {
if(id==null)return null;
Device dev = deviceService.getDispositivo(Long.parseLong(id));
List<Property> props = deviceService.listProperties(dev, 10);
return props;
}
Device Service
@Service("manageDevices")
@Transactional(readOnly=true,propagation=Propagation.REQUIRED)
public class ManageDevicesImpl implements ManageDevices {
private Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private DevicesDAO devicesDAO;
public List<Property> listProperties(Device dev, Integer qty) {
List<Property> props = devicesDAO.pickProperties(dev, qty);
return props;
}
}
DAO
@Repository("devicesDAO")
public class DevicesDAOImpl implements DevicesDAO {
private Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private SessionFactory sessionFactory;
public List<Property> pickProperties(Device dev, Integer qty) {
if(qty >= 0){
log.debug("Open? "+ sessionFactory.getCurrentSession().isOpen());
log.debug("Tx Active? " + sessionFactory.getCurrentSession().getTransaction().isActive());
List<Property> props = dev.getProperties();
if(props != null){
if(props.size() >= qty)
return props.subList(0, qty-1);
else
return props;
}
}
return null;
}
}
The exception occurs in the pickProperties function (DAO Layer), at the line where i try to load the properties (getProperties). In the logs, there is an open session and transaction. Thanks in advance.