Search This Blog

Friday, 28 December 2012

Criterion

In our previous post we saw the Criteria API at its simplest. No select clauses or where clauses. Just the from clause. However without the ability to apply conditions, Criteria as a feature would be of very limited use.

Wednesday, 26 December 2012

Criteria API - the basics

Until now I have used HQL in all the posts we have seen. I decided to go ahead and try the Criteria API. With criteria you create your queries programmatically and not via Strings. In the HQL examples the simplest Query was the select * query.

Sunday, 23 December 2012

HQL and Nested Queries

It is often the case that we need to execute a query based on the results of another query. One way would be to execute the first query, get the results, parse and use them for the second query. The concern here is that since we are not concerned with results of the first query why should we have the application handle that logic ? Instead why not have the database process the two queries together and return to the application only the results of the second query. The results that the application is actually interested in. This can be achieved using inner queries or sub queries.

Thursday, 20 December 2012

SOAP Webservices using Spring -3

As of now we have configured the web service and have also made our contract (or WSDL ) visible to the client. But what happens when the client actually sends a request? How do we handle it?

Wednesday, 19 December 2012

SOAP Webservices using Spring -2

In the previous example we saw how to set up the application and add the WSDL and XSD files needed. We also configured a MessageDispatcherServlet to handle the operations exposed by our web-service.

Tuesday, 18 December 2012

SOAP Webservices using Spring -1

The Spring Web Services project is used for creating document-driven Web services. I decided to create a simple web service that takes a value and returns a value (i.e. no logic - just data transfer) .

Saturday, 15 December 2012

HQL and Dynamic Fetching strategies

We saw in our earlier post that HQL ignores the fetching strategy in our mapping. Consider the below query which fetches an entity with id 1.
public static void testNormalFetch() {
    final Session session = sessionFactory.openSession();

Wednesday, 12 December 2012

Handling exceptions in Spring MVC

Exceptions occur. And when they occur in a web application, it leaves us developers looking very stupid. An Apache Tomcat page showing a stack trace and 500 in bold words makes it even worse for us. Graceful handling of exceptions in a web application makes things a tad better.

Monday, 10 December 2012

The Fetch Plan and the Fetch Strategy.

While studying HQL I came across the following statement:
"HQL and JPA QL ignore any fetching strategy defined in the mapping. But the global fetch plan is not ignored"
What is the strategy and what is the plan here ?

Saturday, 8 December 2012

Group by and having clauses in HQL

In the previous example we saw the aggregate Functions supported in HQL. But reporting is also dependent on grouping. Examples would be max scores of students grouped by their class, most expensive items sold in a shop grouped by material etc.

Thursday, 6 December 2012

HQL and aggregrate functions

We have been testing out the varied hql functions till now. But what if we want aggregation ?
Aggregate queries are almost always  required in applications. Getting the most expensive, the last logged, total hits... whenever any statistics or reporting screens come up, the aggregate queries show up. I decided to start with count functionality:

Tuesday, 4 December 2012

Reading the date in the request parameter

In the previous posts we saw how Spring allows us to accept request parameters as method level parameters for our Controllers. This is all very easy when we are dealing with String parameters like "first name " or "address". But what if we have date of birth?

Sunday, 2 December 2012

The ResourceLoaderAware Interface

In an earlier post we saw how using Spring's ApplicationContext we were able to access and load resources. However having that the ApplicationContext auto-wired in your class so as to allow you to use the Resource Loading functionality may seem a bit of an overkill. We after only need the ability to load resources. So ApplicationContext is out.