Tôi có một thực thể UserProfile mà tôi cần lưu. sau khi lưu thực thể trong cơ sở dữ liệu, tôi nhận được ngoại lệ sau:Bắt Giao dịch không bắt đầu thành công ngoại lệ khi sử dụng Spring Hibernate
Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
Ngoài ra khi tôi thấy bảng thực thể được duy trì thay vì thực hiện khôi phục!
@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;
}
}
Tôi đang sử dụng quản lý giao dịch Hibernate
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
và cấu hình Hibernate của tôi là:
<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>
Can ai pl. cho tôi biết những gì đang xảy ra ở đây?
'@ user354161' xem câu trả lời đã chỉnh sửa và nhận xét từ 'Bozho' – Bitmap