I'm modifying an exising POJO to include a boolean field, and want to display said Categories based on the boolean value.
To do so, I have updated the Hibernate XML configuration and added the fields to the database. My issue is that a HibernateQueryError is thrown on the Criteria.list()
method when returning the data because Hibernate cannot resolve the new field.
Category POJO:
public class Category implements java.io.Serializable {
private long id;
private String name;
private Short displayOrder;
private Boolean enabled;
private Set<Submission> submissions = new HashSet<Submission>(0);
//getters and setters
public Boolean getEnabled(){
return this.enabled;
}
public void setEnabled(Boolean enabled){
this.enabled = enabled;
}
Added mapping to hibernate config:
<hibernate-mapping>
<class name="com.jason.app.hibernate.Category" table="CATEGORY" lazy="false">
... other properties
<property name="enabled" type = "java.lang.Boolean">
<column name="IS_ENABLED" />
</property>
... set mapping configuration
</hibernate-mapping>
and this is the trouble spot:
private boolean hasDisplayOrder;
private boolean isEnabled;
public List<V> list() {
try {
Criteria criteria = getSession().createCriteria(returnedClass());
if (hasDisplayOrder && isEnabled){
criteria = criteria.add(Restrictions.eq("enabled", true))
.addOrder(Order.asc("displayOrder"));
log.info("Category object is enabled, added to criteria");
}
else if (hasDisplayOrder ) {
criteria = criteria.addOrder(Order.asc("displayOrder"));
log.info("Object does not contain enabled method");
}
return criteria.list();
}
catch (RuntimeException re) {
log.error("Could not retrieve list results for class "
+ returnedClass.getSimpleName(), re);
}
return null;
}
The logging statement inside the first conditional triggers in the logs, and then an error message is printed out.
2014-02-12 12:02:49,482 INFO [com.jason.app.manager.BaseManager] Category object is enabled, added to criteria
2014-02-12 12:02:49,489 ERROR [com.jason.app.manager.BaseManager] Could not retrieve list results for class Category
org.hibernate.QueryException: could not resolve property: enabled of: com.jason.app.hibernate.Category
Things I've tried:
- Change data type from boolean to Boolean in
Category
- change type from
boolean
tojava.lang.Boolean
in hibernate config
The web form that this POJO is used for displays just fine if I remove the conditional inside the list()
method above, but it shows all categories regardless of state.
Are there any other options to try out?