[odb-users] Exception : "object not persistent" when trying to load object which does not exist in database

Florent GRATTA gratta at visuol.com
Thu Nov 12 08:12:46 EST 2015


Hello,

I try to do the following call "getMissionByControlledCar("123")" and I 
get the following message in my log: "getMissionByControlledCar object 
not persistent"
I passed to the function a parameter (scanexCarId) that doesn't 
correspond to a row in database. How can I can avoid avoing an 
exception?

td::shared_ptr<Mission> 
ODBCarIdenticationServiceImpl::getMissionByControlledCar(std::string 
scanexCarId)
{
	try
	{
		transaction t (m_db->begin ());
		std::shared_ptr<Mission> _mission (m_db->load<Mission> (scanexCarId));
		t.commit ();
		if(_mission.get() != 0)
		{
			return _mission;
		}
		else
		{
			return nullptr;
		}
	}
	catch (const odb::exception& e)
	{
		m_logger->logError("getMissionByControlledCar " + std::string(e.what 
()));
		return nullptr;
	}
}



More information about the odb-users mailing list