0

I am trying to query my hibernate table for a RunEntity. The first where clause in the query searches for RunEntities where the testName = the passed value testname. In the stacktrace, it mentions that it cannot find a match for type testname in the RunEntity, but the RunEntity object explicitly has a string named testName with setters and getters and @Column notation.

Table setup

CREATE TABLE RunEntity (ID INTEGER IDENTITY,TestNumber INTEGER NOT NULL, TestName varchar(50) NOT NULL, ENVIRONMENT VARCHAR(50) NOT NULL, Source VARCHAR(50), Date TIMESTAMP, RESULTFILES BLOB);

Query

@Query("SELECT r FROM RunEntity r WHERE r.testName = :testname AND r.testNumber = :testnumber AND r.environment = :environment AND r.source = :source")
public List<RunEntity> findByNameNumberEnvironmentSource(
        @Param("testname") String testname,
        @Param("testnumber") int testnumber,
        @Param("environment") String environment,
        @Param("source") String source);

Entity

package com.web_application;

 import java.sql.Timestamp;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Lob;

@Entity
@Table(name = "TESTRUNS")
public class RunEntity {

private int ID;
private int testNumber;
private String testName;
private String environment;
private String source;
private String passOrFail;
private Timestamp date;
private byte[] resultFiles;


@Id
@Column(name = "ID")
@GeneratedValue
public int getID()
{
    return this.ID;
}
public void setID(int ID){this.ID = ID;}

@Column(name="TestNumber")
public int getTestNumber()
{
    return this.testNumber;
}
public void setTestNumber(int testNum){this.testNumber = testNum;}

@Column(name="TestName")
public String testName()
{
    return this.testName;
}
public void setTestName(String testName){this.testName = testName;}

@Column(name="Environment")
public String getEnvironment()
{
    return this.environment;
}
public void setEnvironment(String enviro){this.environment = enviro;}

@Column(name="Source")
public String getSource()
{
    return this.source;
}
public void setSource(String src){this.source = src;}

@Column(name="PassOrFail")
public String getPassOrFail()
{
    return this.passOrFail;
}
public void setPassOrFail(String pOrF){this.passOrFail = pOrF;}

@Column(name="Date")
public Timestamp getDate()
{
    return this.date;
}
public void setDate(Timestamp dates){this.date = dates;}

@Lob
@Column(name="ResultFiles")
public byte[] getResultFiles()
{
    return this.resultFiles;
}
public void setResultFiles(byte[] file){this.resultFiles = file;}

}

Part of stacktrace

Caused by: org.hibernate.QueryException: could not resolve property: testname of: com.web_application.RunEntity [SELECT r FROM com.web_application.RunEntity r WHERE r.testname = :testname AND r.testNumber = :testnumber AND r.environment = :environment AND r.source = :source]
at org.hibernate.QueryException.generateQueryException(QueryException.java:137)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:158)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:126)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:88)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:190)
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:301)
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:236)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1800)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:328)
... 66 more

2 Answers 2

1

Change this

 @Column(name="TestName")
public String testName()
{
    return this.testName;
}

to

@Column(name="TestName")
public String getTestName()
{
    return this.testName;
}

Property access Naming convention is important.Try to use IDE for example (Eclipse Getter-Setter,instead using manually doing it)

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

1 Comment

Thanks for your help, sometimes its hard to see these things when you're too close to the project.
0

Correct your testName() getter to getTestName(). You are using Property Access and have to stick to JavaBeans convention.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.