use spring + jpa + hibernate but cannot persist entity and never throws exception, but tests are passed
===

everyone, this is the first time i ask question here, but i've been finding answers many times when i encounter problems. 
  but this time, i've been testing for a long time and searching for hours. since there' re some similar questions, but after trying, it still work...
  i use springmvc and jpa with hibernate to set up a base project, but the problem is i cannot persist entity into database when i put it into jetty. what's strange is that the junit tests are passed...
  so any one can help me? i'm eager to learn that pass the chance to watche the olympic...

  here is the essential code.
  
db-context.xml

  

      <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
    
    	<!-- DBCP DataSource -->
    	<bean class="org.apache.commons.dbcp.BasicDataSource" id="dataSource"
    		destroy-method="close">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/spring" />
    		<property name="username" value="root" />
    		<property name="password" value="root" />
    	</bean>
    
    	<!-- JPA EntityManagerFactory -->
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="jpaVendorAdapter">
    			<bean id="jpaVendorAdapter"
    				class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="showSql" value="true" />
    				<property name="generateDdl" value="true" />
    				<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
    			</bean>
    		</property>
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<!-- Persistence Context Annotated -->
    	<bean
    		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
    		id="persistenceAnnotationBeanPostProcessor" />
    
    	<!-- Transaction -->
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    		<property name="entityManagerFactory" ref="entityManagerFactory" />
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    	<tx:annotation-driven transaction-manager="transactionManager" />
    
    </beans>


persistence.xml(in META-INF folder)

   

     <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
          http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    	version="2.0">
    
    	<persistence-unit name="persist" transaction-type="RESOURCE_LOCAL">
    		<properties>
    			<property name="hibernate.hbm2ddl.auto" value="create-drop" />
    			<property name="hibernate.show_sql" value="true" />
    			<property name="hibernate.transaction.flush_before_completion"
    				value="true" />
    			<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider" />
    		</properties>
    	</persistence-unit>
    
    </persistence>


Person.java (entity bean)

        @Entity
    public class Person {
    
    	private int id;
    	private String name;
    
    	@Id
    	@GeneratedValue
    	public int getId() {
    		return id;
    	}
    
    	// ..
    
    }

PersonDaoImpl.java

        @Repository
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public class PersonDaoImpl implements PersonDao {
    
    	private EntityManager entityManager;
    
    	@PersistenceContext
    	public void setEntityManager(EntityManager entityManager) {
    		this.entityManager = entityManager;
    	}
    
    	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    	public Person persist(Person person) {
    		entityManager.persist(person);
    		return person;
    	}
    
    	// ...
    
    }

PersonServiceImpl.java

    @Service
    public class PersonServiceImpl implements PersonService {
    
    	private PersonDao personDao;
    	
    	@Inject
    	public void setPersonDao(PersonDao personDao) {
    		this.personDao = personDao;
    	}
    
    	public Person create(Person person) {
    		return personDao.persist(person);
    	}
    
    	// @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
    	public Person save(Person person) {
    		return personDao.merge(person);
    	}
    
    	// ...
    
    }

PersonController.java

        @Controller
    @Scope("prototype")
    @RequestMapping("/person")
    public class PersonController {
    
    	private PersonService personService;
    
    	@Inject
    	public void setPersonService(PersonService personService) {
    		this.personService = personService;
    	}
    	
    	@RequestMapping(value = "/add", method = RequestMethod.POST)
    	public ModelAndView add(@RequestParam("username") String name) {
    		Person person = new Person();
    		person.setName(name);
    		System.out.println(name);  // i can get the value
    		personService.create(person); // nothing happend... throws no Excp
    		ModelAndView mav = new ModelAndView();
    		mav.setViewName("result");
    		mav.addObject("val", person.getName());
    		return mav;
    	}
    	
    }

PersonControllerTest.java

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("/test-context.xml")
    public class PersonControllerTest {
    
    	private PersonController controller;
    	
    	@Inject
    	public void setController(PersonController controller) {
    		this.controller = controller;
    	}
    
           
            // the test passed no matter @Transactional or not, if not, the db get the row
    	@Test(/*expected = NullPointerException.class*/)
    	@Transactional
    	public void testAdd() {
    //		PersonController controller = new PersonController();
    		assertEquals("test", controller.add("test").getModelMap().get("val"));
    	}
    
    }



  and some xml like context and mvc config xml and import declaration are omited, the servie and dao interface, anyone help me ?  I' m waiting !


