springmvc+jpa+springdata中遇到的错误解决办法
2014-10-20 22:55
344 查看
1、
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentServiceBean': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
Validation failed for query for method public abstract boxfish.bean.Student boxfish.service.StudentServiceBean.find(java.lang.String)!
原因:bean类中的扩展查询方法的query语句中的sql语句存在错误。
查询语句应该为select s from Student s where s.id=?1这种样式。其中表明Stduent必须和实体类名完全相同,否则报错。
2、Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query。
原因:事务需求异常。或许是业务逻辑类为注解为@Transactional
样例:
@Repository
@Transactional
public interface StudentServiceBean extends JpaRepository<Student,Long> {
@Query("select s from Student s where s.username=?1")
public Student find(String username);
@Modifying
@Query("update Student s set s.password=?1 where s.id=?2")
public int update(String password, Long id);
}
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentServiceBean': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException:
Validation failed for query for method public abstract boxfish.bean.Student boxfish.service.StudentServiceBean.find(java.lang.String)!
原因:bean类中的扩展查询方法的query语句中的sql语句存在错误。
查询语句应该为select s from Student s where s.id=?1这种样式。其中表明Stduent必须和实体类名完全相同,否则报错。
2、Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query。
原因:事务需求异常。或许是业务逻辑类为注解为@Transactional
样例:
@Repository
@Transactional
public interface StudentServiceBean extends JpaRepository<Student,Long> {
@Query("select s from Student s where s.username=?1")
public Student find(String username);
@Modifying
@Query("update Student s set s.password=?1 where s.id=?2")
public int update(String password, Long id);
}
相关文章推荐
- [解决方案] spring-mvc 400错误解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- SpringBoot JPA MySQL 遇到中文乱码的解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- IIS发布mvc程序遇到的HTTP错误 403.14-Forbidden解决办法
- Spring Data JPA applicationContext.xml 配置文件报错的解决办法
- 解决spring+springMVC+Hibernate+spring-data-jpa懒加载No session问题
- Spring MVC helloWorld中遇到的问题及解决办法
- EF Database First with ASP.NET MVC: Creating the Web Application and Data Models开发遇到问题的解决办法
- Spring data jpa 自定义SQL语句遇到错误Not supported for DML operations
- MVC项目发布到服务器之后遇到的HTTP错误 403.14-Forbidden解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- 发布mvc遇到的HTTP错误 403.14-Forbidden解决办法
- jsf+spring+jpa 程序中遇到的N多异常及解决办法
- 非J2EE 容器环境下Spring +JPA 多持久化单元/多个JAR归档注解实体 的实体扫描问题及解决办法
- 编译busybox-1.3.2的时候遇到的错误解决办法
- 出现 "System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本" 错误的解决办法