• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Criteria across multiple tables

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a legacy database with two tables: Logs and ArchivedLogs. They have identical schemas (LogID, Message, TimePosted, etc...). I have a separate HBM mapping file and Java class for both tables. I'm trying to use Criteria to search both tables and return a single list of results, but I'm having trouble getting the correct syntax. Here is what I tried so far:

Criteria theSearch = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Logs.class);
theSearch.add(Restriction.ge("TimePosted", timeValue));
theSearch.addOrder(Order.asc(TimePosted));
return theSearch.list();

The problem with the above code is that it only searches the Logs table. I could separately run the criteria on ArchivedLogs, but the results wouldn't be sorted properly between the two tables.

So I have two questions:

1. Is there any way in Hibernate to map two tables with identical schemas to the same POJO object?

2. If not, can I use a Criteria query to return results from both POJO objects (one per table)? If so, how? Would using plain HQL be a better option?

Thanks!

David
 
reply
    Bookmark Topic Watch Topic
  • New Topic