I need to get data from database by enum type. I have following enum:
public enum ShopType {
VANS("VANS"), ATTICUS("ATTICUS"), FAMOUS("FAMOUS")
ShopType(String label) {
this.label = label;
}
private String label;
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
In my DAO class i have method which returns list of objects by selected type on jsp
page. On jsp
page i send selected value like String
, is it right?
That how looks my method
@Transactional
public List<Shop> findByType(String type) {
return sessionFactory.getCurrentSession().createQuery("from Shop where type=" + ..... .list();
}
I don't know how to create right query. Enum i store in my database like tinyint.
Here is a model.
@Column(name = "type")
@Enumerated(EnumType.ORDINAL)
private ShopType type;