我有一個UserProfile實體,需要保存。拯救實體數據庫後,我得到以下異常:使用Spring Hibernate獲取事務未成功啓動異常
Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
而且當我看到桌上的實體持久的而不是做一回退!
@Transactional(isolation=Isolation.REPEATABLE_READ)
public class HibernateUserProfileDAO implements UserProfileDAO {
private org.hibernate.SessionFactory sessionFactory;
public UserProfile getUserProfile(int userId) {
org.hibernate.classic.Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
UserProfile userProfile = new UserProfile();
userProfile.setUserName("sury1");
session.save(userProfile);
session.getTransaction().commit();
session.close();
return userProfile;
}
}
我使用Hibernate事務經理
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
和我的休眠配置爲:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com.springheatmvn.domain"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.connection.pool_size">10</prop>
<prop key="hibernate.connection.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
任何人都可以PL。告訴我這裏發生了什麼事?
'@ user354161'請參閱'Bozho'編輯答案和評論 – Bitmap