persistence work

This commit is contained in:
eugenp 2013-08-13 01:11:55 +03:00
parent 380e14bff0
commit f9712c2db4
4 changed files with 8 additions and 6 deletions

View File

@ -2,12 +2,10 @@ package org.baeldung.ex.mappingexception.cause1.persistence.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Foo implements Serializable {
@Id

View File

@ -35,9 +35,11 @@ public class Cause2PersistenceConfig {
public LocalSessionFactoryBean sessionFactory() {
final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(restDataSource());
sessionFactory.setPackagesToScan(new String[] { "org.baeldung.ex.mappingexception.cause2.persistence.model2" });
sessionFactory.setHibernateProperties(hibernateProperties());
// sessionFactory.setPackagesToScan(new String[] { "org.baeldung.ex.mappingexception.cause2.persistence.model" });
// sessionFactory.setAnnotatedClasses(new Class[] { Foo.class });
return sessionFactory;
}

View File

@ -36,9 +36,11 @@ public class Cause3PersistenceConfig {
public LocalSessionFactoryBean sessionFactory() {
final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(restDataSource());
sessionFactory.setAnnotatedClasses(new Class[] { Foo.class });
sessionFactory.setHibernateProperties(hibernateProperties());
// sessionFactory.setPackagesToScan(new String[] { "org.baeldung.ex.mappingexception.cause2.persistence.model" });
sessionFactory.setAnnotatedClasses(new Class[] { Foo.class });
return sessionFactory;
}

View File

@ -2,7 +2,6 @@ package org.baeldung.ex.mappingexception;
import org.baeldung.ex.mappingexception.cause2.persistence.model.Foo;
import org.baeldung.ex.mappingexception.spring.Cause2PersistenceConfig;
import org.hibernate.MappingException;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -21,7 +20,8 @@ public class Cause2MappingExceptionIntegrationTest {
// tests
@Test(expected = MappingException.class)
// @Test(expected = MappingException.class)
@Test
@Transactional
public final void givenEntityIsPersisted_thenException() {
sessionFactory.getCurrentSession().saveOrUpdate(new Foo());