Pages Navigation Menu

Coding is much easier than you think

How to use JQuery dialog as Confirm dialog?

Posted by in jQuery, jQuery UI

  There are quite a few articles you might have read on SimpleCodeStuffs on jQuery like jQuery Tutorial for Beginners, AJAX implementation in Servlets using jQuery and jQuery UI etc.   This example will help you if you have any one of below queries: How to implement “confirmation” dialog in jQuery UI dialog? How to use jQuery UI dialog as JavaScript confirm BOX? How to use JQuery dialog as Confirm dialog? jQuery UI Replacement for alert() Issue: How many times did you have to code some confirmation logic on your website to...

read more

Configuring & Adding Primary Key to Collections in Hibernate

Posted by in Hibernate, Hibernate Annotation

  In previous article we learnt on how to persist a collection of objects of an entity class in a separate table using hibernate. And below are the following two tables are created in the database.     1. STUDENT for Student entity type object 2. Student_lisOfAddress for Address value type object (The default table name for this table gets generated based on – Entity class name_Name of the embeddable object in the entity class). Here ‘Student_ID’ column in Student_lisOfAddress is the foreign key reference of...

read more

Saving Collections in Hibernate

Posted by in Hibernate, Hibernate Annotation | 1 comment

    In our last Hibernate article, we learned about Embedding value object into an entity class. In this article we’re going to focus on saving a Collection in Hibernate.   Consider a scenario where the student have lots of address. So in this case we need to create more no of embedded object in the student class, which is so tedious at certain point. In such case we can use Collection to solve this problem. This collection can be a list, set, map, collection, sorted set, sorted map. Hibernate provides the facility to persist...

read more

Value object & Entity object in Hibernate mapping

Posted by in Hibernate, Hibernate Annotation

So far we have learnt how to write a model object and we learnt to annotate a model object so that hibernate create a table for us, then we learnt how to save, retrieve, update and delete the entity object in the database.     Still now we have created the entity class based on the assumption that each member variable inside the entity class will have a single column in database.   In Above table the type of fields of the class STUDENT CLASS is as below. ID is INTEGER type Name ...

read more

Composite Primary Keys In Hibernate

Posted by in Hibernate, Hibernate Annotation

  If the table has a primary key then in Entity class we configure that column using @Id annotation. Even when the table doesn’t need a primary key, we must configure one column as id (one primary key is must).   Now If the database table has more than one column as primary key then we call it as composite primary key, so if the table has multiple primary key columns , then in order to configure these primary key columns we need to create a new @Embeddable class containing the PK fields:   @Embeddable public class...

read more

Auto Generate Primary key in Hibernate

Posted by in Hibernate, Hibernate Annotation

    In our early tutorials I have used @Id annotation to mark a particular field as primary key, this Primary key is used to fetch data via get or load method. And we set the value of primary key manually each time when we are about to create a new record.   In this article we shall learn to Auto Generate this Primary key value in Hibernate. Before getting into the above topic, let us have a discussion about Natural key and Surrogate key.   Natural Key   A natural key is a single column or set of columns which are...

read more

Difference Between Update and Merge methods In Hibernate

Posted by in Hibernate, Hibernate Annotation | 4 comments

    Often times, you will notice Hibernate developers mix use of session.update() and session.merge() At first look both update() and merge() methods seems similar because both of them are used to convert the object which is in detached state into persistence state, but the major difference between update and merge is that update method cannot be used when the same object exists in the session. Let’s look at those difference with simple example.   Example :-   Student current = (Student)session.get(Student.class,...

read more

Table per Class Hierarchy Using Annotation

Posted by in Hibernate, Hibernate Annotation

  In our previous tutorial we got introduced to Inheritance Mapping In Hibernate, In this article I will explain you about Table per Class Hierarchy Inheritance mapping. By this inheritance strategy, we can map the whole hierarchy in a single table. Here, an extra column otherwise known as discriminator column is created in the table to identify the class. In the table, for each record some columns will be empty; those columns for which the particular Java class does not have fields.     The above is the Hierarchy of classes...

read more

Hibernate 4 Hello World example in Eclipse using Annotation

Posted by in Hibernate | 1 comment

  This is the 4th article on Hibernate in java application that describes on how to to save an object from java into the database using Hibernate 4(Hibernate 4 Insert Query). If you have not read my previous articles article on Generic Hibernate Application Requirements and Steps to be followed to use Hibernate in Java, I will recommend that you read that article first. You may want to look at Hibernate Installation/Setup on Eclipse IDE article if Hibernate is not installed already on your system.   As described earlier, the...

read more

Generic Hibernate Application Requirements – XML Mapping

Posted by in Hibernate, Hibernate XML Mapping

  The objective of this example is to understand the general requirement to be followed in creating any hibernate application in Java. You may want to look at Hibernate Installation/Setup on Eclipse IDE article if Hibernate is not installed already on your system.   In general any hibernate application, must have the following 4 files, Model class Mapping XML Configuration XML One java file to access this configuration file/write our logic These files are the minimum requirement to run an hibernate application, in case of...

read more