'JPA query receive column name not valid
I need to execute a very simply JPA Query
but I receive the error message "column name not valid".
Obviously, if I execute manually the query it works fine, but not if I use JPA.
This is my repository class:
@Repository
public interface OrdersRepositoryPayId extends JpaRepository<OrdersEntityPayId, Long> {
@Query(value="select trackid from orders where payid=:payid" , nativeQuery=true)
OrdersEntityPayId getOrdersByPaymentId(@Param("payid") String payid);
}
And this is the Entity class:
@Entity
@Table(name = "ORDERS")
public class OrdersEntityPayId {
@Id
private Long orderid; // These are the table fields name
private String payid;
private String trackid;
// Getter and setter ....
}
And this is the oracle tabel primaryKey:
Database is Oracle. Table name is ORDERS. PrimaryKey is ORDERS.ORDERID NUMBER(16,0)
Could you pls indicate what I'm wrong? Below the error I received:
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:331) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:551) at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) [..] [..] Caused by: java.sql.SQLException: Nome colonna non valido at oracle.jdbc.driver.OracleStatement.getColumnIndexPrimitive(OracleStatement.java:4257) at oracle.jdbc.driver.OracleStatement.getColumnIndex(OracleStatement.java:4215) at oracle.jdbc.driver.InsensitiveScrollableResultSet.findColumn(InsensitiveScrollableResultSet.java:299) at oracle.jdbc.driver.GeneratedResultSet.getLong(GeneratedResultSet.java:626)
[...]
Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
