Hello,
I am using Hibernate 3.2.3 with JPA and Spring 2.0.
I constructed a trivial application, then wrote a test method. I have two instances and issued two deletes and got an exception
java.lang.IllegalArgumentException: Removing a detached instance
This is expected.
String restaurantName = "Dover Diner";
Restaurant restaurant = restaurantDao.findByName(restaurantName).get(0);
Restaurant rest2 = restaurantDao.findByName(restaurantName).get(0);
restaurantDao.delete(restaurant);
List<Restaurant> results = restaurantDao.findByName(restaurantName);
assertEquals(0, results.size());
restaurantDao.delete(rest2);
Next, I followed Section 2.2. of
http://www.hibernate.org/hib_docs/annot ... ntity.html
and converted the entity to use a composite primary key, i.e. defining a new primary key class and refer to the primary key class from the entity. The unit test is still the same, but now the exception is gone. Instead, there is only an INFO message of
handling transient entity in delete processing
but no exception.
Are there any ways to configure so that Hibernate will throw an exception, so that my application can trap this kind of error?
Regards,
Simon