package org.springframework.showcase.carplant.dao; import org.hibernate.SessionFactory; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; /** * Implementation of the CarPartsInventoryTest specific for Hibernate * (without using Hibernate Template). One should look at the DAO * itself where an @Repository stereotype annotation defines this class * to be a Repository. By using an {@link PersistenceExceptionTranslationPostProcessor} * any exceptions generated by the plain Hibernate API are automatically * translated to the Spring data access exception hierarchy hence preserving * ultimately portability of the CarPartsInventory DAOs by keeping the * technology-agnostic. * * Note that the @Repository annotation does not only work for Hibernate but * also for other data access technologies such as JPA. * * @author Alef Arendsen * @since 2.0.4 */ public class PlainHibernateCarPartsInventoryTest extends AbstractCarPartsInventoryTest { private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } protected CarPartsInventory getCarPartsInventory() { return (CarPartsInventory)applicationContext.getBean("plainHibernateCarPartsInventory"); } @Override protected void flush() { sessionFactory.getCurrentSession().flush(); } // TODO fix this. The exception is thrown, but somehow the test still fails!? // @ExpectedException(DataIntegrityViolationException.class) // public void testNullName() { // getCarPartsInventory().addPart("whatever", "whatever", null); // } }