Reputation: 399
I just want to fetch the data with particular id. My method containing query is:
public static List getidProducts(Integer id) {
List<Products> productsid = Products.find("product_id IN:id").bind("id", id).fetch();
return productsid;
}
I am getting the error: symbol not found and it indicates the error to be in the method find(). Where am i wrong? Pls suggest me.
Here is my products.java
package models;
import java.util.*;
import javax.persistence.*;
import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;
import com.avaje.ebean.*;
import java.sql.*;
public class Products extends Model {
@Id
public Integer product_id;
@Constraints.Required
public String productname;
@Constraints.Required
public Integer quantity;
@Constraints.Required
public Integer price;
public static Finder<Integer,Products> find = new Finder<Integer,Products>(Integer.class, Products.class);
public static List getidProducts(Integer id) {
return Products.find().where().in("id", id).findList();
}
}
Upvotes: 0
Views: 166
Reputation: 55798
Is this still Ebean ? Weird aproach, try this:
public static List<Products> getidProducts(Integer id) {
return Products.find.where().in("product_id", id).findList();
}
Nota bene isn't your product_id unique field? In such case, you should return a Products object not List.
public static Products getidProducts(Integer id) {
return Products.find.where().eq("product_id", id).findUnique();
}
or simplier:
public static Products getidProducts(Integer id) {
return Products.find.byId(id);
}
Upvotes: 1