|
|
|
catch(Exception e){
System.out.println(e.getMessage());
}
finally{
// Actual contact insertion will happen
at this step
//session.flush();
session.close();
}
}
} |
Here is the sample code that shows Programmatic configuration of hibernate.
Configuration config = new Configuration()
.addResource(“roseindia/tutorial/hibernate/
contact.hbm.xml “)
Configuration config = new Configuration()
.addClass(roseindia.tutorial.hibernate.Contact.class)
.setProperty(“hibernate.dialect”,
“org.hibernate.dialect.MySQLDialect “)
.setProperty(“hibernate.connection.driver_class”,
“ com.mysql.jdbc.Driver “)
. . . SessionFactory sessions =
config.buildSessionFactory(); |
In the next section, you will see how to run
and test the Hibernate-application.
Running the Hibernate Application
In previous section, we wrote the code for
developing a Hibernate application. Now you
will see, how this application is to be run and
tested.
To run the example you should have the Eclipse
IDE and Hibernate on your machine.
Hibernate is free open source software it can
be download from http://www.hibernate.org/
6.html. Visit the site and download Hibernate
3.0. You can download the Hibernate and install
it yourself but we have provided all the necessary
files in one zip file. Download the example-code and library from here and extract the content
in your favorite directory say |
|
“C:\hibernateexample”. Start the
Eclipse.exe project and do the following steps
shown below:
1. Once you have opened the Eclipse, open File menu, go to New and select Project option. Then click the Next button on the
displayed dialog.
2. In the next dialog, give the project name
as HibernateExample to the Project name
command line, and click the Finish button.
|
|
Dec
2007 | Java Jazz Up |32 |
|
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63 ,
64,
65 ,
66 ,
67 ,
68 ,
69 ,
70 ,
71 ,
72 ,
73 ,
74 ,
75 ,
76 ,
77 ,
78 ,
79 ,
80 ,
81 ,
82 , Download PDF |
|
|
|
|
|
|
|
|
|