These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: When are PersistenceExceptions thrown? (newbie question)
PostPosted: Mon Jun 14, 2010 12:57 pm 
Newbie

Joined: Sat Dec 05, 2009 1:34 am
Posts: 12
I have an integration test method that should throw the following exception (because of a unique constrain on the email column of the users table):

Code:
javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException


Here is the test:

Code:
@Test
@ExpectedException(PersistenceException.class)
public void save_UserTestDataUpdateUserNonUniqueEmail_PersistenceException() {
      User powerUser = dao.findById("poweruser");
      powerUser.setEmail("kuser@null.com");
      dao.save(powerUser);
}


But no exception is thrown! I am using Spring Test and so the unit of work will be rolledback at the end of the method.

However, if AFTER the dao.save(...) call I make a call to flush() or FindAll()....then I get my exception.

Is this the way it is supposed to work?


Top
 Profile  
 
 Post subject: Re: When are PersistenceExceptions thrown? (newbie question)
PostPosted: Sat Jul 03, 2010 12:17 am 
Newbie

Joined: Sat Dec 05, 2009 1:34 am
Posts: 12
Yes -- this is the way it is supposed to work. There is even a warning about this in the Spring Test documentation. Always do a flush to ensure you don't get a false positive.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.