Oh I get it, so I should be testing for null, and if it returns null than I
ought to throw that type of exception.
Michael Horwitz wrote:
>
> Hi,
>
> According to the Hibernate Javadoc what you are seeing is the expected
> behaviour. Session->get() returns null if no such entity exists in the
> database?
>
> Mike
>
> On 12/1/06, maskkkk <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hello,
>>
>> I'm trying to retrieve a record that does not exist in a unit test.
>>
>> When I do so Hibernate does not throw a DataAccessException (I'm using
>> Appfuse 1.9.4)
>>
>>
>> "In failing in my Unit Test wrote:
>> >
>> > ...
>> > public void testAddAndRemoveComment() throws Exception
>> > {
>> > Comment c = new Comment();
>> >
>> > // Test setting assignment of a LogEntry
>> >
>> > c.setParentObjectID(new Long(1));
>> >
>> > // Test setting the comment text
>> > c.setCommentText("comment text");
>> >
>> > dao.saveObject(c);
>> >
>> > assertNotNull(c.getId());
>> >
>> > log.debug("Removing Comment: " + c.getId());
>> >
>> > dao.removeComment(c);
>> >
>> > try
>> > {
>> > log.debug("Attempting to retrieve deleted
>> object.");
>> > c = dao.getComment(c.getId());
>> > assertNull(c);
>> > log.error("Deleted Comment not null: " + c);
>> > fail("Comment Object found in Database.");
>> > }catch(Exception ex)
>> > {
>> > assertTrue("object deleted exception",
>> ex.getCause()
>> instanceof
>> > ObjectDeletedException);
>> > }
>> >
>> > }
>> > ...
>> >
>>
>>
>> In my Hibernate DAO wrote:
>> >
>> > ...
>> > public Comment getComment(Long commentId) throws
>> DataAccessException
>> > {
>> > return (Comment)
>> getHibernateTemplate().get(Comment.class,
>> commentId);
>> > }
>> > ....
>> >
>>
>>
>> output in log wrote:
>> >
>> > Deleted Comment not null: null
>> > Comment Object found in Database.
>> >
>>
>> Thank you,
>>
>> Andrew J. Leer
>> --
>> View this message in context:
>> http://www.nabble.com/DataAccessException-not-thrown...-tf2741002s2369.html#a7647854
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/DataAccessException-not-thrown...-tf2741002s2369.html#a7676855
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]