-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Criteria query linking one-to-many using a value not a class
PostPosted: Tue Jul 19, 2005 10:56 am 
Newbie

Joined: Tue Jul 19, 2005 10:33 am
Posts: 3
Location: Omaha, Ne
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.SOWTemplate

SOWTemplate 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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 11:11 am 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
You capitalized the "D" in "templatedegrees" in your mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 11:34 am 
Newbie

Joined: Tue Jul 19, 2005 10:33 am
Posts: 3
Location: Omaha, Ne
After correcting naming problem... thanks by the way, I'm getting this error:
Error 500: #{sowSearchPage.doSearchButtonAction}: javax.faces.el.EvaluationException: org.springframework.orm.hibernate3.HibernateSystemException: collection was not an association: com.msiinet.spa.model.SOWTemplate.templatedegrees; nested exception is org.hibernate.MappingException: collection was not an association: com.msiinet.spa.model.SOWTemplate.templatedegrees


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 2:20 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
I don't think you can create an alias there. Have you tried simply adding your Restriction on that property directly?

c.add( Restrictions.in("templateDegrees", (List)temp) );

If you really want it to be treated like a separate entity you could always just map it as such, like you're doing with your other bags.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 19, 2005 3:44 pm 
Newbie

Joined: Tue Jul 19, 2005 10:33 am
Posts: 3
Location: Omaha, Ne
thanks for your input but leaving out the alias results in a
Bad SQL grammar [] in task 'Hibernate operation'; nested exception is COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] CLI0100E Wrong number of parameters. SQLSTATE=07001

Anne


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.