What is cascade in Hibernate?

Friday, February 26, 2010 Posted by Gayath Chaminda 0 comments
Cascade specifies which operations should be casecaded from the parent object to the associated object. These values can be applied for association specified in the hbm files.

The meaningfull values are;

1) cascade="none" the default, tells Hibernate to ignore the association.

2) cascade="save-update" cascades save and update actions from the parent to the child. In other words it tells Hibernate to navigate the association when the transaction is committed and when an object is passed to save() or update() and save newly instantiated transient instances and persist changes to detached instances.

3) cascade="delete" cascades the delete action from the parent to the child or tells Hibernate to navigate the association and delete persistent instances when an object is passed to delete().

4) cascade="all" means to all actions are cascaded from the parent to the child. Cascade both save-update and delete, as well as calls to evict and lock.

5) cascade="all-delete-orphan" means the same as cascade="all" but, in addition, Hibernate deletes any persistent entity instance that has been removed (dereferenced) from the association (for example, from a collection). All actions are cascaded from the parent to the child, orphan children are deleted.

6) cascade="delete-orphan" Hibernate will delete any persistent entity instance that has been removed (dereferenced) from the association (for example, from a collection).

Leave your comment here ...
Labels:

Beginner guide to Java Language

Wednesday, February 3, 2010 Posted by Gayath Chaminda 0 comments
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture,Java philosophy of "Write Once, Run Everywhere" make Java become one of the popular programming languages today. Becasue of this reason, java application runs in various environments, PC, Smart Cards, Games, Printers, ...etc.

If you heard about Java, you may confused with word JDK, Java2, J2SE, J2EE, Java Applet, Java Runtime Environment, ...etc. So, better to first clarify those. Actually Java is a programming platform specification published by Sun Microsystems which can be implemented by any other pary and current platform specification is Java2. Java Standard Edition (Java SE) is core java implementation that provides "real" or "basic" java language support. If you are new to java programming language on PC, this is the first point you should start. Java Development Kit (JDK) is implementation of java2 platform specification by Sun Microsystem, other vendors have implemented their versions of JDk but Sun's JDK is totoally free and most populer. The current version of JDk is JDk6 update 16 (At the time of writing this article). JDK can be considered as tool that can be used for implement java programming language or java compiler. In addition to Java SE, Sun resealses another two version for different application domains, Java Enterprise Edition (Java EE) and Java Micro Edition (Java ME). Enterprise Edition is can be considered as addition to the Java SE for Enterprise Application Development and Micro Edition is to develop application for mobile devices such as Celliuler Phones, PDAs, ...etc. Java Euntime Envieonment is collection of libraries that available in different platforms in order to run java applications. JRE knows how to convert java class file content (byte codes) in to platform specific instructions. This is how java achieved "Write Once, Run Anywhere (WORA)" paradigm. With Java SE you can develope two kinds of java programs, Java Application and Java Applets. These two approaches full fills different programming requirments.

I hope that now you have some sort of clear idea about java language. So, lets taste java programming language with some example. Hence from here on wards, I uses sun's JDk as development tool (You can download latest version of JDK from sun's web site [http://java.sun.com] and install in to you PC). As java is compile language, source code files are included in file with .java extension and compile using java compiler tool and finally generates file with .class extention. .class file can be used to run the java program and get the result. So, JDk provides several tools to manipulate java programs. Following are useful tools;

• Compiler name javac
• Launcher or interpreter to run Java applications, called java
• Java debugger called jdb
• Viewers applet called appletviewer
• Disassembler for file.class named javap
• Generators for API documentation is called javadoc
• Manage JAR files (Java Archive) named jar

The steps making Java Programs

1. Making the program text (source-code) with the Java language syntax. You can type in source-code in any text editor and save it with ".java" extension.
2. To compile the text into a Java application program.
3. Running Java applications with compiler or the applet, the applet viewer if the shape

You have to follow above steps though it applet or application. But following is java application implementation as an example. Select your populer text editor(Notepad, vi editor, Notepad++, ..etc) to write following lines and make sure to save file as Hello.java . Since java is a case sensetive language you have to pay attention to case sensitivity too. Note that you don't have to type number with dot in front of each line, this is just for explanation purpose.


public class Hello {
public static void main (String [] args) {
// Display message
System.out.printIn ( "Hello, world!");
}
}

Description:

1. The first line: make a class named "Hello". The entire framework in Java is always in the class
2. The name of the class must always be the same as the file name
a. In the first line, is the Hello class name and file name are Hello.java
b. Not allowed to use a different name, eg file name replaced with Halo.java. This will cause an error during compilation

3. On the second line written method main (). This method has an array of String parameters. This is a String array argument of Java programs.
a. A Java application program must have the main part, a method called main ()
b. Method main () function as a starting point of the program. That is, when the Java program is run, method main () always run the first time
4. In the third row, there are comments
a. Comments will not be compiled and run
b. Compiler will ignore the comment lines
c. Comment line begins with a slash character uses two "//". (comments by early signs "/ /" should only be on one line)

5. The fourth line is the command to display the message
a. The message of the string "Hello, world!" Displayed by the method called printIn ()
b. PrintIn method () is part of the variable named out
c. Meanwhile, out is part of the class named System
d. To call the dot operator (".") is used to System.out.printIn ()

The process for compiling Java programs are:

1. Once finished creating the Java file, the next step is to compile a file using javac.exe (Being in the bin directory, If you install JDk6 at C:\Program Files\Java\jre1.6.0_16 then javac.exe (also other supportive tools) resides in C:\Program Files\Java\jre1.6.0_07\bin directory. Hence if you issue javac command with java file name you have to copy your source file in to bin directory or inlcude bin directory in to your system path (Temporaly you can set path in windows environment using, set path=%path%;).

2. Running the compiler command in the command-prompt

> Javac Hello.java

3. Hello.class which generated files are output files from the compilation results

Hello.class files can be directly run the program using java.exe.

> java Hello

Hello World

Finally the result obtained, first java program ran. Now you can explore more on java language. If you encountered any difficulties please comment.
Labels: