Hibernate Query Wizard for Netbeans 5.0

Hibernate is equipped with an extremely powerful query language that (quite intentionally) looks very much like SQL. But don't be fooled by the syntax; HQL is fully object-oriented, understanding notions like inheritance, polymorphism and association.

HQL Wizard for NetBeans 5.0 helps to create selects in HQL. The wizard is part of hibernate plugin based on xdoclet. The project pages are on nbxdoclet website. The HQL wizard can be open be using code completion of hibernate bean's (POJO) facade class.

The wizard is shown bellow:

Detailed steps how to create the query in the example:

  1. To create first join select USER -> N-1: Address address property in entities view and click to Add button. The address is added to Entities list.
  2. To add first Left Parameter select address -> town item and click to Add button.
  3. Type ? to First right parameter.
  4. To create second join select User -? N-1: Car car item and click to Add button.
  5. Add two user -> age rows. It is similiar like adding car -> type row.
  6. To add first parentheses select car.typ="fiat" and user.age > 20 rows and click to Set Or button.
  7. To add second parentheses select user.age < 50 and user.age > 20 rows and click to Set And button.
  8. Change generated method name to getFiatForTown.

After click to Ok button code, shown bellow, is generated to facade class:

 public java.util.List getFiatForTown(java.lang.String addressTown) {
        Session session = store.HibernateUtil.currentSession();
        org.hibernate.Query query = session.createQuery(
                " select user " +
                " from  " +
                " User as user " +
                " join user.address as address " +
                " join user.car as car " +
                "  where  " +
                " address.town = ? " +
                "  and  (car.type = \\"fiat\\" " +
                "  OR  (user.age < 50 " +
                "  AND user.age > 20) " +
                " ) ");
        query.setParameter(0,addressTown);
        
        return query.list();
    }

The wizard read the information about entities (POJO) from xdoclet tags. It it not so difficult to implement reading of EJB30 annotations. I'm not sure if someone wants to use it with annotations. Is this wizard handy? Please give me feedback and report bugs to nbxdoclet's bug tracing system.

Comments:

Post a Comment:
Comments are closed for this entry.
About

xzajo

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today