HQL
Hibernate provides a simplified language for querying into the database. Its called HQL-Hibernate Query language.
We can use SQL Queries directly in hibernate,So naturally a question may come.Whats the need of using HQL if you can perform the same with SQL ?
1.HQL is very simple. Its very easy to learn and manipulate.
2. HQL engine generates the most appropriate SQL for a particular task from a set of SQL statements.
3.Usage of HQL will help in application portability. We can change the Database from say Oracle to MySQL without changing any HQL queries. Only change needed is in the Configuration file where we need to specify the appropriate driver and dialect.
These are some of the advantages of using HQL. I will keep you updated with more advantages soon.
iText
iText is the free and open source library in Java used for generating PDF, RTF and HTML documents. It is very simple to use and manipulate. For the .NET framework there is iTextSharp similar to iText.
iText was developed by Bruno Lowagie in 1998. If you are interested in the history and what made him develop iText, Visit More on iText .
You can easily tryout the following piece of code provided you have JDK and any IDE. Download the iText.jar from and add it to the project .You can download the jar file from here.
Sample code:
/*Importing the necesary packages*/
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;
import java.io.FileOutputStream;
/*Sample code for creating a new pdf document and writing into it
*@author guru_G
*/
public class SampleCode{
public static void main(String[] args) {
try{
Document pdf = new Document();
/**
*This will create a new document in the following
*path D:\ with name Document.pdf
**/
FileOutputStream file=new FileOutputStream("D:\\Document.pdf");
PdfWriter.getInstance(pdf,file);
pdf.open();
/*Adding a new paragraph in the document*/
pdf.add(new Paragraph("Manchester United"));
pdf.close();
}catch(Exception e){
System.out.println("Exception caught :"+e.getMessage());
}
}
}
Run the project and a new file will be created in D:\ with name document.pdf .
Pointers
Learn hibernate from Gavin King,Christian Bauer and team. They are the creators of hibernate. Recently i read about Gavin, he has only 5 years of experience working with Java and went on to create a framework of this magnitude.Infact knowledge of Java is not the essential thing you need to learn Hibernate.You have Nhibernate if you are a fan of .NET technologies. Gavin and Christian are presently working for the JBoss project and he is also an active member of the EJB spec. group.
Visit Hibernate home page Hibernate Core
Read the documentation .
There are also many tutorials available in the web. wait..!!! I am gonna post a tutorial in Hibernate where i will help you in each and every step of learning hibernate.
PS: I am having some problems with my Eclipse IDE. ie y the delay in posting the tutorial
An introduction to Hibernate
Hey all, I am gonna talk abt Hibernate..!!! Its a java persistence frame work. In simple words its an ORM tool.
Whats ORM and whats an ORM tool..?? ORM stands for Object Relational Mapping..its mapping between objects and database. we normally use JDBC to talk 2 database from Java. Using an ORM tool like Hibernate we map java objetcs to Database. In Hibernate tables are denoted as classes and relationships are denoted by objects. there are a few terms we need to understand when we are using Hibernate.
- POJO Classes- Plain Old Java Objects
These are java equivalent of the database tables, the columns in the tables are represented as member variables of the particular class with access specifer Private..all these member variables willl have getter and setter methods. The class also consists of a default constructor .We normaly add two parametrised constructors. one consisting of all the members in the class another consisting of member variables which are mandatory(ie: columns which are NOT-NULL in table).
- HBM- Hibernate Mapping File
An xml file defining the table structure.using the various tags available, we can define the entire schema.
- Hibernate CFG -configuration file
Using the Configuration file we can specify the dilaect, the schema to which we need to connect, the driver to be used, the connection pool size etc etc.
-
Archives
- February 2012 (1)
- July 2009 (1)
- June 2009 (1)
- May 2009 (7)
-
Categories
-
RSS
Entries RSS
Comments RSS