I am trying to execute Hibernate Filter.
Here is my POJO class:
@Entity
@Table(name="flight")
@FilterDef(name="f1",parameters=@ParamDef(name="status",type="String"))
@Filter(name="f1",condition="status=:p1")
public class Flight
{
@Id
@Column(name="flightno")
private int flightNumber;
@Column(name="src", length=10)
private String source;
@Column(name="dest",length=10)
private String destination;
@Column(name="status",length=10)
private String status;
//setter & getters
}
And here is my Main class code :
public static void main(String[] args)
{
//code for getting SessionFactory Object
Session session=factory.openSession();
Transaction tx=session.beginTransaction();
Query query=session.createQuery("from Flight f");
Filter filter=session.enableFilter("f1");
filter.setParameter("p1","DELAYED");
List list=query.list();
Iterator itr=list.iterator();
while(itr.hasNext())
{
Flight f=(Flight)itr.next();
System.out.println("FLIGHT NO:"+f.getFlightNumber());
System.out.println("SOURCE :"+f.getSource());
System.out.println("DESTINATION :"+f.getDestination());
System.out.println("STATUS :"+f.getStatus());
session.close();
}
But i am the output like this:
Exception in thread "main" java.lang.IllegalArgumentException: Undefined filter parameter [p1]