Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Java Hibernate Cookbook
  • Table Of Contents Toc
  • Feedback & Rating feedback
Java Hibernate Cookbook

Java Hibernate Cookbook

By : Prajapati, Ranapariya
close
close
Java Hibernate Cookbook

Java Hibernate Cookbook

By: Prajapati, Ranapariya

Overview of this book

This book will provide a useful hands-on guide to Hibernate to accomplish the development of a real-time Hibernate application. We will start with the basics of Hibernate, which include setting up Hibernate – the pre-requisites and multiple ways of configuring Hibernate using Java. We will then dive deep into the fundamentals of Hibernate such as SessionFactory, session, criteria, working with objects and criteria. This will help a developer have a better understanding of how Hibernate works and what needs to be done to run a Hibernate application. Moving on, we will learn how to work with annotations, associations and collections. In the final chapters, we will see explore querying, advanced Hibernate concepts and integration with other frameworks.
Table of Contents (10 chapters)
close
close
9
Index

Executing a subquery using a criteria


In this recipe, we will take a look at how to use subquery. Here, we will do the same thing as before; we will use the DetachedCriteria class provided by the hibernate API. The DetachedCriteria class works in detached mode and is used to create a criteria query when the session is not available, as we can execute DetachedCriteria with the existing session object.

How to do it…

We will create one scenario to show how DetachedCriteria acts as a subquery.

The scenario is to get all the products whose categories have been recently added.

The preferred solution for this problem is as follows:

  • First, we will create DetachedCriteria to find the maximum createdOn date

  • Then, we will use the result of the first query to check the date of the product's category

Consider the following code:

Code

/* Line 1 */ DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Category.class);
/* Line 2 */ detachedCriteria.setProjection(Projections.max("createdOn"));

/* Line 4...
Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Java Hibernate Cookbook
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon