mmoore
asked on
Hibernate get or load not raising HibernateException when record not found
I am trying to do:
I am deliberately passing a key that should result in a "not found", or something like that.
When I use get, program=null, when I use load, all program class variables are null.
Using Hibernate-2.1
public static Tprogram findProgramByKey( Long key) throws DataAccessException
{
Tprogram program = null;
try
{
program = (Tprogram)HibernateSessionConfig.getCurrentSession().load(Tprogram.class, key);
}
catch( HibernateException e )
{
LOGGER.error( "Unable to find program for key = "+ key, e);
throw new DataAccessException( e);
}
return program;
}
I am deliberately passing a key that should result in a "not found", or something like that.
When I use get, program=null, when I use load, all program class variables are null.
Using Hibernate-2.1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem is, it does not throw ANY exception.Well, i'm wondering why you were trying to catch one then? ;)
I can't speak with authority as i don't know that API, but not finding a datum would seldom be a reason for an exception
ASKER
Well, I found the java doc and basically it says if the record is not found, null will be returned. So it's working just fine. http://docs.jboss.org/hibernate/orm/3.5/javadocs/org/hibernate/Session.html#get(java.lang.Class, java.io.Serializable)
Thanks for pointing me in the right direction. I'm an old programmer, but new to the web technologies.
Thanks for pointing me in the right direction. I'm an old programmer, but new to the web technologies.
:)
ASKER
Open in new window
and this works, however, I'm guessing there is a better way to do it.Mike