@Service
@Repository
@Transactional
public class VideoService {
@PersistenceContext
EntityManager entityManager;
public void save(Video video) {
Video video1 = new Video();
entityManager.persist(video1);
}
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="video_pu" transaction-type="RESOURCE_LOCAL" >
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
</persistence>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/video" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="video_pu"/>
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- post-processors for all standard config annotations -->
<context:annotation-config/>
트랜잭션 서비스 메서드 save (비디오 비디오)는 절대로 시작되지 않으므로 커밋되지 않습니다. 오류는 어디에 있습니까? EntityManagerFactory를 사용할 때 완벽하게 작동하지만 명시 적으로 트랜잭션을 시작하고 커밋하고 싶지 않습니다. @Transactional 주석과 함께 사용하고 싶습니다.EntityManager + @Transactional
오류가 있습니까? –
나는 트랜잭션 주석을 적용 할 인터페이스를 사용해야한다고 확신한다. 'VideoService'와'VideoServiceImpl' – beerbajay