Web site management - Defining the global fetch plan parsed and validated
Defining the global fetch plan parsed and validated at compile time, whereas HQL expressions aren t parsed until runtime (or startup, if externalized named queries are used). The nice thing about the Hibernate CriteriaAPI is the Criterion framework. This framework allows extension by the user, which is more difficult in the case of a query language like HQL. Note that the Criteria API is native to Hibernate; it isn t part of the Java Persistence standard. In practice, Criteria will be the most common Hibernate extension you utilize in your JPA application. We expect that a future version of the JPA or EJB standard will include a similar programmatic query interface. Querying by example As part of the Criteria facility, Hibernate supports query by example (QBE). The idea behind query by example is that the application supplies an instance of the queried class, with certain property values set (to nondefault values). The query returns all persistent instances with matching property values. Query by example isn t a particularly powerful approach. However, it can be convenient for some applications, especially if it s used in combination with Criteria: Criteria criteria = session.createCriteria(User.class); User exampleUser = new User(); exampleUser.setFirstname(”John”); criteria.add( Example.create(exampleUser) ); criteria.add( Restrictions.isNotNull(”homeAddress.city”) ); List result = criteria.list(); This example first creates a new Criteria that queries for User objects. Then you add an Example object, a User instance with only the firstname property set. Finally, a Restriction criterion is added before executing the query. A typical use case for query by example is a search screen that allows users to specify a range of different property values to be matched by the returned result set. This kind of functionality can be difficult to express cleanly in a query language; string manipulations are required to specify a dynamic set of constraints. The Criteria API and the example query mechanism are discussed in more detail in chapter 15. You now know the basic retrieval options in Hibernate. We focus on the object-fetching plans and strategies for the rest of this section. Let s start with the definition of what should be loaded into memory.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.