Hibernate spring

Solo disponible en BuenasTareas
  • Páginas : 16 (3854 palabras )
  • Descarga(s) : 0
  • Publicado : 15 de septiembre de 2010
Leer documento completo
Vista previa del texto
1

The author has made every effort in the preparation of this book to ensure the accuracy of the information. However, information in this book is sold without warranty either expressed or implied. The author will not be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.

Hibernate, Spring, Eclipse, HSQL Database & Maven tutorial
Hibernateis a very popular ORM (Object to Relational Mapping) tool and Spring is a very popular IOC (Inversion Of Control) container with support for AOP, Hibernate etc.

by

K. Arulkumaran & A. Sivayini

Website: http://www.lulu.com/java-success Feedback email: java-interview@hotmail.com

2 Table Of Contents Notations..................................................................................................................... 3 Tutorial 4 – Hibernate, HSQL Database, Maven and Eclipse ........................ 4 Tutorial 5 – Spring, Hibernate, Maven and Eclipse........................................ 20 Tutorial 6 – Spring AOP......................................................................................... 31

3 Notations
Command prompt:

Eclipse:

File Explorer orWindows Explorer:

Internet Explorer:

4 Tutorial 4 – Hibernate, HSQL Database, Maven and Eclipse This tutorial assumes that you are familiar with Java, Eclipse and Maven. If not please refer Tutorials 1-3 at http://www.lulu.com/content/1080910. This tutorial is a continuation of Tutorial 1 (Java, Eclipse and Maven).
Hibernate is an ORM (Object to Relational Mapping) tool, so we need arelational database. To keep things simple, I will be using HypersonicSQL (aka HSQL) database, which is easy to use. This is an open source database, which can be found at http://hsqldb.sourceforge.net/. Also check http://hsqldb.org.

The three types of persistent tables are MEMORY tables, CACHED tables and TEXT tables. I will be using the default MEMORY tables where data is held entirely in memorybut any change to their structure or contents is written to the .script file. The script file is read the next time the database is opened, and the MEMORY tables are recreated with all their contents. So MEMORY tables are persistent. It is important to remember that the data in memory is written to the .script file when you shutdown your database properly/naturally by executing SQL “SHUTDOWN(COMPACT | IMMEDIATELY”. The saved file will load the data into memory the next time the HSQLDB server starts up. But if you stop the HSQLDB server abruptly in the command line by pressing [Ctrl] + [C] the data will not be written to the script file and consequently lost. Refer documentation for CACHED & TEXT tables. Install HSQL database into c:\java folder from http://hsqldb.sourceforge.net/.Download the hsqldb_1_8_0_7.zip and unpack it into your c:/java folder.

5
Start the HSQL database server by executing the following command in a command prompt as shown below: C:\java\hsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.Server

Since I have not given any database name and or alias (refer HSQLDB document and/or type C:\java\hsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.Server -? For moredetails), it defaults to “test” as the database name & alias. After starting the HSHQL database server the following files are created under “C:\java\hsqldb” test.lck, test.log, test.properties. Open up another command prompt and start the DatabaseManager, with which you can execute SQLs. If you are new to SQL, then this is handy to practice and gain some SQL skills. Note: You need to have the HSQLDBserver running before you can open the DatabaseManager. C:\java\hsqldb>java -cp ./lib/hsqldb.jar org.hsqldb.util.DatabaseManager

This will spawn a new window as shown:

6
Select “HSQL Database Engine Server” and click “Ok”. Now you should have the following window opened, where you can type in your SQL and execute it by clicking on the “Execute” button. The results will be shown at the...
tracking img