我正在使用Spring JPA Repository,无法执行查询
这是我的java代码:
public interface TbBamiVacationRepository extends JpaRepository<TbBamiVacation,String>{
@Modifying
@Query(value = "select user_id,reassign_to from tb_bami_vacation a where to_date1 >=to_date(:toDate, 'DD-MON-YYYY') and to_date(:toDate, 'DD-MON-YYYY') >=from_date and to_date(:toDate, 'DD-MON-YYYY') <=to_date1 and user_id='112'",nativeQuery=true)
List<TbBamiVacation> findReassignedTo( @Param("toDate")String toDate);
//toDate="26-MAR-2017"
}
我的日志:
Hibernate: select user_id,reassign_to from tb_bami_vacation a where to_date1 >=to_date(?, 'DD-MON-YYYY') and to_date(?, 'DD-MON-YYYY') >=from_date and to_date(?, 'DD-MON-YYYY') <=to_date1 and user_id='112'
org.springframework.orm.jpa.JpaSystemException: could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:155)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:417)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:111)
Caused by: java.sql.SQLException: Invalid column name
at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:3677)
at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:2749)
at oracle.jdbc.driver.OracleResultSet.getString(OracleResultSet.java:494)
at org.apache.tomcat.dbcp.dbcp2.DelegatingResultSet.getString(DelegatingResultSet.java:266)
at org.apache.tomcat.dbcp.dbcp2.DelegatingResultSet.getString(DelegatingResultSet.java:266)
提前致谢!!
答案 0 :(得分:0)
删除&#39; a&#39;从这里:
from tb_bami_vacation a where
变化:
@Param("toDate")
为:
@Param("to_date1")