-->
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.  [ 2 posts ] 
Author Message
 Post subject: Confusion with Examples in criteria creation
PostPosted: Tue Sep 21, 2004 9:57 am 
Newbie

Joined: Fri Mar 26, 2004 4:19 pm
Posts: 3
Please pardon my "simple" question. I'm having a conceptual problem with the Example.create functionality when creating a criteria and I've been unable to find the answer in the FAQ or other supporting documents.

In my application it is common for users to want to query the database with an example of the object they'd like so I wrote a little wrapper around Hibernate code to shield them from the complexities if they don't need it:
Code:
public class myQueryTool{
[...]
  public List looksLike(Object queryObject){
   
    Session s = null;
    Transaction tx = null;
    List returnList;
   
    try{
      s = factory.openSession();
      tx = s.beginTransaction();

      returnList = s.createCriteria(queryObject.getClass())
      .add(Example.create(queryObject)
      //.enableLike(MatchMode.ANYWHERE)
      .ignoreCase()
      .excludeZeroes()
      )
      .list();
    }
    catch (HibernateException he){

    [...]

[I've played around a bit with adding and removing ".enableLike" and other options to Example, but have had no luck]

Unfortunately, this doesn't do what I thought it did. For example, if I'd like to find a "run" that is a part of a "logbook" I thought this would work:
Code:
public List findRunsWithLogbook(Logbook logbook){

      prad.database.schema.Run run = new prad.database.schema.Run();
      run.setLogbook(logbook);
      List runList = myQueryTool.looksLike(run);
      return runList;
}

I thought this would return a list of all runs that have an entry in the database pointing to the associated logbook.

Instead, this returns a list of all runs in my database, not just those with the correct associated logbook. [If my error is subtle enough that you need the .hbm.xml files let me know ... I suspect it's easier than that.]

I really appreciate your help .. and apologize again if this is a no-brainer. Somehow my brain is lost.

Thanks,

stephen[/code]


Top
 Profile  
 
 Post subject: can't search by an association using Example API
PostPosted: Wed Sep 22, 2004 4:54 pm 
Beginner
Beginner

Joined: Fri Mar 26, 2004 8:19 am
Posts: 49
the only fields that will be respected in an Example query are those members in the base class. So you can't set an association and search on all objects matching that association! I asked Gavin for this already....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.