Hibernate get or load not raising HibernateException when record not found

I am trying to do:
        
        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;
    	}

Open in new window


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
LVL 3
mmooreAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
I can't find the javadoc for that class but  make sure it DOES throw that exception. The exception is unchecked so your compiler won't tell you if it doesn't
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mmooreAuthor Commented:
The problem is, it does not throw ANY exception.  As a hack I am now doing ...
    		if (program == null) {
    			LOGGER.error( "Unable to find program for key = "+ key);
    			throw new DataAccessException( "Program does not exist. " + key);
            }

Open in new window

and this works, however, I'm guessing there is a better way to do it.
Mike
0
CEHJCommented:
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
0
mmooreAuthor Commented:
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.
0
CEHJCommented:
:)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.