Determining the primary key property name using Hibernate

Simple method:

String idPropertyName = sessionFactory.getClassMetadata(User.class).getIdentifierPropertyName();

To get the actual value see this tutorial

Elaboration
Continue reading “Determining the primary key property name using Hibernate”

Annotated Dependency Injection / Inversion of Control (DI / IoC) in Spring 3 Web MVC using Netbeans

This tutorial will detail how to insert services and components (Dependency Injection) into a Spring 3 Web MVC Netbeans application.

The process used is Dependency Injection (DI) or Inverse of Control (IoC) whereby Spring will instantiate (or inject) certain components at runtime rather than at having them initiated at compile time.  This provides a highly decoupled design which facilitates ‘change’ more easily. Importantly, it also makes comprehensive Unit Testing (with Mock Objects) much easier to achieve. IoC is a conventional design pattern.

This tutorial is quite comprehensive in that it will simulate CRUD operations on ‘Person’ objects. For simplicity, it does not used a database, data will be put stored in the ‘HttpSession’ object instead.

The code is available for download at the bottom of this page. Continue reading “Annotated Dependency Injection / Inversion of Control (DI / IoC) in Spring 3 Web MVC using Netbeans”

Spring 3 Web MVC – Friendly URL using RequestMapping variable URI

Following on from a previous tutorial on getting a hello world Spring 3 Web MVC application running in Netbeans here, this tutorial will explain how to achieve friendly URL’s incorporating variables.

E.g.

http://localhost:8084/HelloSpring/person?name=John

becomes

http://localhost:8084/HelloSpring/person/John
Continue reading “Spring 3 Web MVC – Friendly URL using RequestMapping variable URI”

Hello Spring 3 Web MVC using Netbeans

6-Nov-2014 –> Please note that a new blog now exists for Spring 4 Web MVC using Maven and Netbeans with Java configuration (no XML at all) here – John

This tutorial will simply detail one correct way to create a simple Spring 3 web application using Netbeans.

Note: The Spring plugin for Netbeans (that is being distributed with Netbeans 7.7.1 and previous) is actually designed for Spring 2 and is therefore somewhat misleading. This tutorial overcomes that giving you the correct way to generate a Spring 3 web project.

A fully working Netbeans project is available for download at the bottom of the page.

Continue reading “Hello Spring 3 Web MVC using Netbeans”