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.
How to implement "confirmation" dialog in jQuery UI dialog?
Issue: How many times did you have to code some confirmation logic on your website to ensure that your users are sure about the action they are about to perform?
There is nothing wrong with this above code. However, it is plain. You cannot customize it with CSS make it look consistent with your site's colour and identity.
jQuery UI has the solution for you. You can use the jQuery UI Dialog to present users with customized confirmation/dialog boxes as shown below.
Firstly, let's add the necessary jQuery libraries in the head section of the Jsp page.
The code above instantiates the dialog box and assigns it two buttons. The"Yes"and"No"buttons. The "Yes" is responsible for submitting the form to the server.
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.
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 Student tables 'ID'. In next article we shall learn to override the default collection class table name and to add primary key to it.
In this post we shall learn on how to change this default table name and foreign key name of collection table and how to add primary key to this table to identify each record separately.
To do this we need to add @JoinTable annotation before the collection in Entity class as show below.
In parameter of @JoinTable table we specify name of table and name of joinColumns (i.e foreign key) with another annotation @JoinColumn. When you run the test program with the above changes, the following quires are displayed in eclipse console which have our overridden table name primary key name.
To inset the primary key collection table I have modified the collection element in Entity class as shown below.
Since the primary key is to be created at collection table, we use the @CollectionId instead of @Id annotation before the collection in Entity class.
With the @GenericGenerator annotation, we will to give some information to @CollectionId and tell how it should work. First off, we name this GenericGenerator whatever we like, for my example I just named it "myGenerator" but this is completely up to you. We also tell it what ID generation strategy to use, in this case I used "INCREMENT" strategy.
Oh, and let's not forget to point our @GeneratedValue annotation to our newly minted customer @ CollectionId via the generator="myGenerator" property.
Address.java and hibernate.cfg.xml and HibernateUtil.java is the same as previous post.
On running the Hibernate test class with above changes, the collection table gets created as below.
Here ADDRESS_ID is the primary key which gets generated due to above code change.
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 the collections object via @ElementCollection annotation.
Defines a collection of instances of an embeddable class, this annotation must be specified if the collection is to be mapped by means of a collection table.
hibernate.cfg.xml will be the same as in previous article.
When you run the above program two tables are created in database, first table is for Student entity "STUDENT" and second table is for the embeddable object (Address) – "Student_lisOfAddress" (The default table name for this table gets generated based on – Entity class name_Name of the embeddable object in the entity class).
Here the 'Student_ID' column in 'Student_lisOfAddress' is the foreign key reference of Student tables 'ID'. In next article we shall learn to override the default collection class table name and to add primary key to it.
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.
Here STUDENT CLASS have a field Address object, this means in the database there are no meaning for Address object, as this Address object in turn have four other fields like.
Now the question is how can we save this address object into the database.
One way of saving the Address Object is to treat the member variable of address objects as the member variable of Student object itself.
Here without having a Student object the use of Address object doesn't make any sense. So the purpose of address object is just provide value to the Student object; And this is what differentiate an Entity object from a Value object.
So what the heck is Value object?
Entity object is the one which have meaning on its own, where a value object has no meaning on its own, the value object belongs to an entity instance and its persistent state is embedded in the table row of the owning entity.
In the above example the Student object represents an Entity object and Address object represents a Value object.
Now in order to make this class of value type, and in order to tell hibernate not to create a separate table for address class, I have used @Embeddable annotation in the Address class, Also we need to use @Embedded annotation in the member variable of Address object in Student entity class as shown below.
So far we have seen that an Entity Type Object Student has a Value Object(or Embeddable Object ) ADDRESS with corresponding fields name street, city, pin-code and state save to the database table STUDENT with value object's column name (CITY_NAME, PIN_CODE, STATE_NAME, STREET_NAME).
Suppose in the above scenario if a Student have two addresses like Local Address and Permanent Address then how to manage the column names of these two value objects in the database table STUDENT.
In order to overcome this problem, we have to override the Attribute name of the Value objects. Hibernate has provided @AttributeOverride annotation for this purpose.
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).
The primary key class must be public.
If property-based access is used, the properties of the primary key class must be public or protected.
The primary key class must be serializable. We shall explore the reason for implementing this interface in our upcoming tutorial.
A composite primary key must be represented and mapped as an embeddable class (EmbeddedId Annotation).
We shall explore the concept behind this composite primary keys in the next article.