No transaction starts within Spring @Transactional method

后端 未结 3 803
悲&欢浪女
悲&欢浪女 2021-01-06 06:24

I run into strange problem while developing application using Spring (3.0.5), Hibernate (3.6.0) and Wicket (1.4.14). The problem is: i cannot save or modify any object into

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-06 07:19

    a) You are defining both a Hibernate SessionFactory and a JPA EntitymanagerFactory. Which is it going to be? Either use Hibernate's Session API or JPA's Entitymanager API with Hibernate as provider, but not both.

    b) You have defined a HibernateTransactionManager, but since you are using EntityManager in your code, you need a JpaTransactionManager instead:

    
        
    

    Here's a commented version of your applicationContext.xml:

    
    
    
        
         
    
        
            
            
            
                      
        
    
        
        
            
            
        
    
        
        
             
                
            
            
                 pl.m4ks.comics
            
        
         
    
         
        
            
                
            
        
    
        
        
    
        
    
    

    And a design note: DAOs shouldn't be transactional. You should use a service layer that manages the transactions. See this question (and many others) for reference.

提交回复
热议问题