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]