Announcement Announcement Module
Collapse
No announcement yet.
Hibernate Query by example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate Query by example

    Hi,

    Does anyone know whether Query By Example is supported in Spring.
    If so could you please give a sample code.

    I am using Spring 1.2.4 and hibernate 3.

    I couldnt find any functions from the HibernateTemplate for executing the crieteria queries..

    Any help is appreciated....


    Thanks
    Jil
    Last edited by jil; Jun 7th, 2006, 08:05 AM.

  • #2
    You can use the execute() method with a HibernateCallback. Inside that callback you have access to the hibernate session and all of its functionality.

    Regards,
    Andreas

    Comment


    • #3
      Originally posted by jil

      I couldnt find any functions from the HibernateTemplate for executing the crieteria queries..

      Jil
      in method in class that extends HibernateTemplate

      Criteria criteria = getSession().createCriteria(CaptainBeefHeartsAlbum s.class);
      ....
      ....
      ....
      List troutMaksReplicas = criteria.list();

      Comment


      • #4
        As a side note, some methods were removed since HibernateTemplate became too large and some methods were used only in some corner cases.

        Comment


        • #5
          Thanks a lot for all who replied

          I am able to implement QBE using spring...here goes my code ..


          List list = getHibernateTemplate().executeFind(new HibernateCallback() {
          public Object doInHibernate(Session session) throws HibernateException {

          Example example = Example.create(fnsearch).ignoreCase().excludeZeroe s().enableLike(MatchMode.ANYWHERE);;



          List results= session
          .createCriteria(BookDetails.class)
          .add(example).list();


          return results;
          }
          });

          Comment

          Working...
          X