0

getting

com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'partnerIdPartner'.

application.properties:

spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl 

Table creation:

CREATE TABLE [partnersystem] ( [idPartnerSystem] INT IDENTITY(1,1) , [partner_idPartner] INT NOT NULL DEFAULT NULL , [Name] NVARCHAR(45) NULL DEFAULT NULL , [Domain] NVARCHAR(45) NULL DEFAULT NULL , [Code] NVARCHAR(45) NULL DEFAULT NULL , [PartnerSystem_idSystem] INT NOT NULL DEFAULT NULL , [UpdateUser] NVARCHAR(45) NULL DEFAULT NULL , [UpdateDT] DATETIME NULL DEFAULT NULL , CONSTRAINT [partnersystem_PRIMARY] PRIMARY KEY CLUSTERED ([idPartnerSystem]), CONSTRAINT [partnersystem_fk_PartnerSystem_partner] FOREIGN KEY ("partner_idPartner") REFERENCES "partner" ( "idPartner" ) ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT [partnersystem_fk_PartnerSystem_System] FOREIGN KEY ("PartnerSystem_idSystem") REFERENCES "system" ( "idSystem" ) ON UPDATE NO ACTION ON DELETE NO ACTION); CREATE INDEX [partnersystem_fk_PartnerSystem_partner] ON [partnersystem] ([partner_idPartner]); CREATE INDEX [partnersystem_fk_PartnerSystem_System] ON [partnersystem] ([PartnerSystem_idSystem]); 

JPA Entity:

@Entity @Table(name = "partnersystem") public class PartnerSystem { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "idPartnerSystem") private int idPartnerSystem; @Column(name = "partner_idPartner" ) private int partnerIdPartner; @Column(name = "Name") private String name; @Column(name = "Domain" ) private String domain; @Column(name = "Code" ) private String code; @Column(name = "PartnerSystem_idSystem" ) private int partnerSystemIdSystem; @Column(name = "UpdateUser" ) private String updateUser; 

my repository:

 @Repository public interface PartnerSystemRepository extends JpaRepository<PartnerSystem, Integer>{ public PartnerSystem findByPartnerIdPartner(int partnerIdPartner); } 

executing simple query throws an error.

public List<Object[]> findAllPartnerSystem(int id) { String test = "SELECT idPartnerSystem, partnerIdPartner, name, domain, code, partnerSystemId" + " FROM PartnerSystem " + "WHERE partnerIdPartner = ?" ; Query query = em.createNativeQuery(test); query.setParameter(1, id); List<Object[]> results = query.getResultList(); for (Object[] row : results) { } return results; } 

1 Answer 1

1

In native queries you have to use the column name not the property name:

"SELECT idPartnerSystem, partner_idPartner, name, domain, code, PartnerSystem_idSystem" + " FROM partnersystem " + "WHERE partner_idPartner= 

But I suggest using JPQL queries and not native queries.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! i am new to spring! i will defiantly take a look in to JPQL queries

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.