hibernate version 3.0
This is my mapping setup for a parent table sowtemplate and its children, goals, tasks and degrees.
<class name="com.msiinet.spa.model.SOWTemplate" table="sowtemplate" >
<id name="id" type="integer" column="id" unsaved-value="-1">
<generator class="identity"/>
</id>
<timestamp column="stamp" name="stamp" />
<property name="title" type="string" column="title"/>
<property name="solution" type="string" column="solution_desc" />
<property name="scope" type="string" column="scope_desc" />
<property name="deliverables" type="string" column="deliverable_desc" />
<property name="completionCriteria" type="string" column="completion_desc" />
<property name="price" type="double" column="price" precision="22" scale="0" />
<property name="customerResponsibilities" type="string" column="customer_resp_desc" />
<property name="comments" type="string" column="comment" />
<bag name="goals" inverse="true" order-by="id" cascade="all">
<key column="templateid" />
<one-to-many class="com.msiinet.spa.model.Goal" />
</bag>
<bag name="tasks" inverse="true" order-by="id" cascade="all">
<key column="templateid" />
<one-to-many class="com.msiinet.spa.model.Task" />
</bag>
<bag name="templateDegrees" table="templatedegrees">
<key column="templateid" />
<element column="name" type="string" />
</bag>
</class>
This mapping saves, updates and deletes correctly. My issue is with using the Criteria for searches. This is the code I’m using.
Code:
public List findSOWByMap(final HashMap map) {
List l = (List) getHibernateTemplate().execute(
new HibernateCallback() {
public Object doInHibernate(Session session) {
Criteria c = session.createCriteria(SOWTemplate.class);
Object temp = (String)map.get("keyword");
boolean keywordSelected = false;
String text = null;
String type = "";
if (temp != null) {
keywordSelected = true;
text = ((String)temp).toUpperCase();
type = (String)map.get("keyword_type");
if (type != null) {
if (type.equals(SearchConstants.ALL_TEXT)) {
//all sow text
//Restrictions.disjunction for "OR" conditions Restrictions.adjunction for "AND" conditions
c.add( Restrictions.disjunction()
.add( Restrictions.like("title", '%'+text +'%').ignoreCase() )
.add( Restrictions.like("solution", '%'+text +'%').ignoreCase() )
.add( Restrictions.like("scope", '%'+text +'%').ignoreCase() )
.add( Restrictions.like("deliverables", '%'+text +'%').ignoreCase() )
.add( Restrictions.like("completionCriteria", '%'+text +'%').ignoreCase() )
.add( Restrictions.like("customerResponsibilities", '%'+text +'%').ignoreCase() )
.add( Restrictions.like("comments", '%'+text +'%').ignoreCase() ));
} else if (type.equals(SearchConstants.TITLE)) {
//title
c.add( Restrictions.like("title", '%'+text +'%').ignoreCase() );
} else if (type.equals(SearchConstants.PROJECT_GOALS)) {
//goals
c.createAlias("goals", "gls");
c.add( Expression.like("gls.description", '%'+text +'%').ignoreCase() );
}
}
}
temp = (List)map.get("practice");
if (temp != null) {
//practice
c.add( Restrictions.in("practice",(List)temp));
}
temp = (List)map.get("degrees"); //THIS IS WHERE THE ISSUE IS
if (temp != null) {
//degrees
List l = (List)temp;
c.createAlias("templatedegrees", "dgs");
c.add( Restrictions.in("dgs", (List)temp) );
}
temp = (SolutionArea)map.get("solution");
if (temp != null) {
//solutions
if (!keywordSelected) {
c.createAlias("goals", "gls");
} else if (!type.equals(SearchConstants.PROJECT_GOALS)) {
c.createAlias("goals", "gls");
}
c.add( Expression.eq("gls.solutionArea", temp) );
}
c.addOrder( Order.asc("title") );
return c.list();
}
}
);
return l;
}
This works properly for all criteria except the templatedegrees search.
It returns the following message:
Error 500: #{sowSearchPage.doSearchButtonAction}: javax.faces.el.EvaluationException: org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: templatedegrees of: com.msiinet.spa.model.SOWTemplate; nested exception is
org.hibernate.QueryException: could not resolve property: templatedegrees of: com.msiinet.spa.model.SOWTemplateSOWTemplate contains a List of templateDegrees.
Code:
private List templateDegrees = new ArrayList();
I know this is going a bit long... but any help you could give is greatly appreciated.
Thanks,
Anne