Technical Jargon

"Its fun to learn"- guru_G

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.

May 24, 2009 Posted by | Hibernate, Technical | , , | Leave a Comment

Lazy Loading in Hibernate

Lazy loading is a functionality provided by Hibernate. What lazy loading does is that it doesn’t load the the associated objects for a class during startup. They will be loaded only when they are referenced. This lazy loading greatly improves the application performance. In hibernate 3.0, lazy loading is enabled by default. ie:by default the objects are only loaded as and when they are referenced. To say this in XML terms in hibernate 3.0 lazy=”true” by default for objects and lazy=”false” for collections. This default behavior of hibernate may throw in some exception called LazyInitializationException. This is a very famous exception and to whoomever you ask for an answer the default answers would be
1. setting lazy=”false” for all
2.Use session.get() instead of session.load.
:)
I don’t think the first one can be called a solution as setting lazy=”false” is like forcing the hibernate to work without one of its most important feature.Also it degrades the performance. If the no of tables and the underlying relations are huge, then it will take a hell lot of time to perform some task. So what we can do is to
keep lazy as true and load the associated objects as and when we need it.

[Please bear with me for the time being, i will post the examples for all these once ma IDE is working fine.Till then i will continue with the theory aspect of it.]

The second one is to be used whether or not u get a Lazy Exception.I say this because method load() returns an exception in case of a null object while method get() returns a null object in the same case. So its better to use session.get() for all cases. If you are so much interested in using session.load() do it if and only if you are sure that such an object exists.

Lazy Exception can be a hard nut to crack if you don’t understand the underlying reason of it. Lazy Exception can also occur due to improper session management ie: trying to access the session after closing it.

May 24, 2009 Posted by | Hibernate, Technical | , , | Leave a Comment

Chrome Commercial

May 24, 2009 Posted by | Uncategorized | , , | Leave a Comment

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 .

May 24, 2009 Posted by | Technical | , , | Leave a Comment

   

Follow

Get every new post delivered to your Inbox.