2013-07-29 2 views
0

주소를 업데이트하고 싶습니다.스프링 데이터 jpa 쿼리 문자열 오류

@Modifying 
@Query("update UserInfo u set u.address = ?1 where u.username = ?2") 
void setAddress(String address, String username); 

하지만 작동하지 않습니다.

org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: 
|Exception Description: No transaction is currently active; nested exception is 
javax.persistence.TransactionRequiredException: |Exception Description: No transaction 
is currently active 

는 그리고 내 쿼리 문자열이 예외를 차지 이유 알 수없는 소스

말한다?

업데이트 쿼리에서 mutiple 필드를 업데이트하는 방법?

@Query("update UserInfo u set u.address = ?1, u.phoneNumber = ?2 where u.username = ?3") 

답변

0

없음 트랜잭션이 현재 활성화, 그래서 그냥 봄에게 주석을 추가하지 않습니다, 이것은 당신이 DB와 ​​ORM 변경할 수 있습니다, 당신은 같은 종류의 아래 문맥을 만들어야합니다 첫 번째 트랜잭션

@Modifying 
@Transactional 
@Query("update UserInfo u set u.address = ?1 where u.username = ?2") 
void setAddress(String address, String username); 
0

입니다 트랜잭션 관리자가 있습니다. 그런 다음 @Transactional 주석을 메서드에 사용하십시오.

<bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="dataSource" ref="dataSource" /> 
    <property name="jpaVendorAdapter"> 
     <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"> 
      <property name="generateDdl" value="true" /> 
      <property name="database" value="HSQL" /> 
     </bean> 
    </property> 
    <property name="persistenceUnitName" value="jpa.sample" /> 
</bean> 

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory" /> 
</bean> 

<jdbc:embedded-database id="dataSource" type="HSQL" /> 
관련 문제