0

I have two classes,a POJO and a main class and i'm working with named query with annotation in hibernate.

the POJO class is as follows

@NamedQueries(
        {
            @NamedQuery(
                    name="findEmployeeName",
                        query="from Employeenam e where e.name=:name" 
                    )
        }
)
@Entity
@Table(name = "employee")
public class Employeenam {

    // public String tostring(){return id+" " +name+ " " +salary+ " " +job;}

    @Id
    @GeneratedValue
    @Column(name = "id")
    int id;

    @Column(name = "name")
    String name;

    @Column(name = "salary")
    int salary;

    @Column(name = "job")
    String job;

    public int setId() {
        return id;
    }

    public void getId(int Id) {
        this.id = Id;
    }

    public String setName() {
        return name;
    }

    public void getName(String Name) {
        this.name = Name;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int Salary) {
        this.salary = Salary;
    }

    public String setJob() {
        return job;
    }

    public void getJob(String Job) {
        this.job = Job;
    }

}

and the main class as:

public class FetchData {
    public static void main(String[] args) {

        Configuration configuration = new Configuration();
        configuration.configure("hibernate.cfg.xml");
        SessionFactory sfactory = configuration.buildSessionFactory();
        Session session = sfactory.openSession();
        Query query = session.getNamedQuery("findEmployeeName");
        query.setString("name", "dfdsf");
        Employeenam e = new Employeenam();
        List<Employeenam> empList = query.list();
        session.close();
    }
}

I am getting the following error as

Parameter id does not exist as a named parameter in [from Employeenam e where 
 e.name=:name]

Can someone please help me with this.. where am i going wrong AGAIN??

Taky
  • 5,284
  • 1
  • 20
  • 29
Ezhil
  • 261
  • 2
  • 10
  • 31
  • My gess is thta the code that you're actually executing contains the line `query.setString("id", "dfdsf");` instead of `query.setString("name", "dfdsf");`. Check that you have recompiled your code. – JB Nizet Feb 12 '13 at 08:03

1 Answers1

3
public int setId() 
{
    return id;
}

public void getId(int Id) {
    this.id = Id;
}

You have incorrectly coded the getter and setter methods for ID. getId should return int instead of setId.

user1972796
  • 374
  • 3
  • 7