Skip to main content

Posts

Showing posts from September, 2014

Hibernate Annotation Example with Java Collection Mapping

Hi Guys, Many a times we have data required to be mapped in the collection framework. Like suppose if we talk about a simple example of student table where a student is having having fields such as students(sid, same, dateofbirth, qualification). Now if we want to have some more information to be stored about student such as the number of courses he/she has enrolled, the marks obtained in the different subjects, the reference email IDs so on and so forth, then, these information can't be stored in the single table and corresponding single fields can't also be able to handle all these information. Given the complexity of the situation we are going to separate these information in different tables such as courses, emails, marks, phones and references. The schema of all these tables would probably be as follows: students(sid, sname, dob, qualification); courses(sid, cname, idx); emails(sid, emailid, idx); marks(sid, marks); phones(sid, phoneno); refs(sid, rname,...

Struts2 and Hibernate Example using Annotation

Hi Guys, Today we are going to create an example using Struts2 and Hibernate using Annotation. For the database, we are going to use MySQL. This example will register a record for a user in the mysql database, which later will be used to login to the application. First of all we need to create our database table in MySQL. Log into your mysql database and type the following command to create a database in the mysql prompt. create database mydb; Use the above created database to create table. use mydb; Now we need to create a database table named "users". create table users( uid int primary key auto_increment, uname char(15), password char(20), email char(20), phone long, city char(15)); Now to create this application, we are going to use eclipse. Open your eclipse and create a dynamic web project. Put the following jars related to Struts2 and Hibernate in the WEB-INF/lib folder Now create the following packages in the src folder for the ...