I’m building a demo API with spring boot and I’m getting this error when I make the request with path…
“/user/names”
Hibernate:
{call db_user..sp_test_nombres()}
2023-09-14T09:43:31.819-04:00 WARN 14928 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S1093
2023-09-14T09:43:31.819-04:00 ERROR 14928 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : El nombre de columna id no es válido.
2023-09-14T09:43:31.836-04:00 ERROR 14928 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.orm.jpa.JpaSystemException: Unable to find column position by name: id [El nombre de columna id no es válido.] [n/a]] with root cause
com.microsoft.sqlserver.jdbc.SQLServerException: El nombre de columna id no es válido.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:237) ~[mssql-jdbc-11.2.3.jre17.jar:na]
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.findColumn(SQLServerResultSet.java:729) ~[mssql-jdbc-11.2.3.jre17.jar:na]
at com.zaxxer.hikari.pool.HikariProxyResultSet.findColumn(HikariProxyResultSet.java) ~[HikariCP-4.0.3.jar:na]
at org.hibernate.sql.results.jdbc.internal.AbstractResultSetAccess.resolveColumnPosition(AbstractResultSetAccess.java:65) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.query.results.ResultsHelper.lambda$resolveSqlExpression$0(ResultsHelper.java:64) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.query.results.DomainResultCreationStateImpl.resolveSqlExpression(DomainResultCreationStateImpl.java:280) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.query.results.ResultsHelper.resolveSqlExpression(ResultsHelper.java:58) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.query.results.implicit.ImplicitFetchBuilderBasic.buildFetch(ImplicitFetchBuilderBasic.java:97) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.query.results.implicit.ImplicitFetchBuilderBasic.buildFetch(ImplicitFetchBuilderBasic.java:37) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.query.results.DomainResultCreationStateImpl.visitIdentifierFetch(DomainResultCreationStateImpl.java:432) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
at org.hibernate.sql.results.graph.entity.AbstractEntityResultGraphNode.afterInitialize(AbstractEntityResultGraphNode.java:48) ~[hibernate-core-6.2.7.Final.jar:6.2.7.Final]
(...continue)
That path should execute a simple stored procedure that queries for usernames. The stored procedure is the following:
ALTER PROCEDURE sp_test_nombres
AS
BEGIN
SELECT
first_name
FROM
personas_2
END
This is the model:
package com.apirestdemo.test.models;
import jakarta.persistence.*;
@Entity
@Table(name="personas_2")
public class UserModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private Long id;
@Column
private String firstName;
@Column
private String lastName;
@Column
private String email;
public Long getId(){
return id;
}
public void setId(Long id){
this.id = id;
}
public String getFirstName() {return firstName;}
public void setFirstName(String firstName) {this.firstName = firstName;}
public String getLastName() {return lastName;}
public void setLastName(String lastName) {this.lastName = lastName;}
public String getEmail() {return email;}
public void setEmail(String email) {this.email = email;}
}
And this is the Repository:
package com.apirestdemo.test.repositories;
import com.apirestdemo.test.models.UserModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
@Repository
public interface IUSerRepository extends JpaRepository<UserModel, Long> {
@Query(value="{call db_user..sp_test_nombres()}", nativeQuery = true)
ArrayList<UserModel> nombres();
}
In properties I have set the following:
spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
What could be wrong?