CodePudding user response:
Can't, can only return void or int/IntegerCodePudding user response:
Such as the following definition
Public interface UserRepository extends JpaRepository{
@ Modifying
@ Query (value="HTTP://https://bbs.csdn.net/topics/INSERT INTO user (username, age, address) VALUES (?,?,?,?,? 1,? 2.? 3) ", nativeQuery=true)
The User insertUser (String username, int the age, the String address);
}
When using an error
Org. Springframework. Dao. InvalidDataAccessApiUsageException: Modifying the queries can only use void or int/Integer as the return type. ; Nested exception is Java. Lang. IllegalArgumentException: Modifying the queries can only use void or int/Integer as the return type.
The at org. Springframework. Orm. Jpa. EntityManagerFactoryUtils. ConvertJpaAccessExceptionIfPossible (EntityManagerFactoryUtils. Java: 374)
The at org. Springframework. Orm. Jpa. Vendor. HibernateJpaDialect. TranslateExceptionIfPossible (HibernateJpaDialect. Java: 257)
The at org. Springframework. Orm. Jpa. AbstractEntityManagerFactoryBean. TranslateExceptionIfPossible (AbstractEntityManagerFactoryBean. Java: 528)
The at org. Springframework. Dao. Support. ChainedPersistenceExceptionTranslator. TranslateExceptionIfPossible (ChainedPersistenceExceptionTranslator. Java: 61)
The at org. Springframework. Dao. Support. DataAccessUtils. TranslateIfNecessary (DataAccessUtils. Java: 242)
The at org. Springframework. Dao. Support. PersistenceExceptionTranslationInterceptor. Invoke (PersistenceExceptionTranslationInterceptor. Java: 153)
The at org. Springframework. Aop. Framework. ReflectiveMethodInvocation. Proceed (ReflectiveMethodInvocation. Java: 186)
The at org. Springframework. Data. Jpa. Repository. Support. CrudMethodMetadataPostProcessor $CrudMethodMetadataPopulatingMethodInterceptor. Invoke (CrudMethodMetadataPostProcessor. Java: 149)
The at org. Springframework. Aop. Framework. ReflectiveMethodInvocation. Proceed (ReflectiveMethodInvocation. Java: 186)
The at org. Springframework. Aop. Interceptor. ExposeInvocationInterceptor. Invoke (ExposeInvocationInterceptor. Java: 95)
The at org. Springframework. Aop. Framework. ReflectiveMethodInvocation. Proceed (ReflectiveMethodInvocation. Java: 186)
The at org. Springframework. Aop. Framework. JdkDynamicAopProxy. Invoke (JdkDynamicAopProxy. Java: 212)
At com. Sun. Proxy. $Proxy115. InsertUser (Unknown Source)
At sun. Reflect. NativeMethodAccessorImpl. Invoke0 (Native Method)
At sun. Reflect. NativeMethodAccessorImpl. Invoke (NativeMethodAccessorImpl. Java: 62)
At sun. Reflect. DelegatingMethodAccessorImpl. Invoke (43) DelegatingMethodAccessorImpl. Java:
The at Java. Lang. Reflect. Method. Invoke (498) Method. The Java:
The at org. Springframework. Aop. Support. AopUtils. InvokeJoinpointUsingReflection (AopUtils. Java: 344)
The at org. Springframework. Aop. Framework. JdkDynamicAopProxy. Invoke (JdkDynamicAopProxy. Java: 205)
At com. Sun. Proxy. $Proxy118. InsertUser (Unknown Source)
At com. Example. Demo. Domain. UserRepositoryTest. InsertUser (UserRepositoryTest. Java: 26)
At sun. Reflect. NativeMethodAccessorImpl. Invoke0 (Native Method)
At sun. Reflect. NativeMethodAccessorImpl. Invoke (NativeMethodAccessorImpl. Java: 62)
At sun. Reflect. DelegatingMethodAccessorImpl. Invoke (43) DelegatingMethodAccessorImpl. Java:
The at Java. Lang. Reflect. Method. Invoke (498) Method. The Java:
The at org. Junit. Runners. Model. FrameworkMethod $1. RunReflectiveCall (FrameworkMethod. Java: 59)
The at org. Junit. Internal. Runners. Model. ReflectiveCallable. Run (ReflectiveCallable. Java: 12)
The at org. Junit. Runners. Model. FrameworkMethod. InvokeExplosively (FrameworkMethod. Java: 56)
The at org. Junit. Internal. Runners. Statements. InvokeMethod. Evaluate (InvokeMethod. Java: 17)
The at org. Springframework. Test. The context. Takeup. Statements. RunBeforeTestExecutionCallbacks. Evaluate (RunBeforeTestExecutionCallbacks. Java: 74)
The at org. Springframework. Test. The context. Takeup. Statements. RunAfterTestExecutionCallbacks. Evaluate (RunAfterTestExecutionCallbacks. Java: 84)
The at org. Springframework. Test. The context. Takeup. Statements. RunBeforeTestMethodCallbacks. Evaluate (RunBeforeTestMethodCallbacks. Java: 75)
The at org. Springframework. Test. The context. Takeup. Statements. RunAfterTestMethodCallbacks. Evaluate (RunAfterTestMethodCallbacks. Java: 86)
The at org. Springframework. Test. The context. Takeup. Statements. SpringRepeat. Evaluate (SpringRepeat. Java: 84)
The at org. Junit. Runners. ParentRunner. RunLeaf (ParentRunner. Java: 366)
The at org. Springframework. Test. The context. Takeup. SpringJUnit4ClassRunner. RunChild (SpringJUnit4ClassRunner. Java: 251)
The at org. Springframework. Test. The context. Takeup. SpringJUnit4ClassRunner. RunChild (SpringJUnit4ClassRunner. Java: 97)
At org. Junit. Runners. ParentRunner $4. The run (331) ParentRunner. Java:
The at org. Junit. Runners. ParentRunner $1. The schedule (ParentRunner. Java: 79)
The at org. Junit. Runners. ParentRunner. RunChildren (ParentRunner. Java: 329)
The at org. Junit. Runners. ParentRunner. Access the $100 (66) ParentRunner. Java:
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull