Java Reference
In-Depth Information
9.
Also inspect the Employee table in MySQL to verify if the new employee has been successfully
added, as shown in Figure 9-16.
figure 9-16
How It Works
1.
It begins with installing all the necessary JARs to use both Hibernate and MySQL. The
hiber-
nate.cfg.xml
file contains all the Hibernate configuration details that will be used by the
ses-
sionFactory
object to set up a database connection. Note that Hibernate will communicate with
the MySQL database using JDBC. The following properties were set:
hibernate.connection.driver_class: JDBC driver class
hibernate.connection.url: JDBC URL
hibernate.connection.username: database user
hibernate.connection.password: database user password
hibernate.connection.pool_size: maximum number of pooled JDBC connections
2.
By setting the
show_SQL
property to
true
, the SQL commands generated by Hibernate are dis-
played in the console. This is very handy for debugging. The
dialect
property allows you to spec-
ify which SQL language should be used to communicate with the relational database, for example,
Oracle9Dialect
,
PostgreSQLDialect
,
SybaseDialect
, and so on. Since you are working with a
MySQL database, it was set to
MySQLDialect
. By setting the
hibernate.current_session_con-
text_class
property to
thread
, the Hibernate session is executed in the thread in which it was
created. The
<mapping class="Employee" />
statement then defined the class for which you
want to create the mapping to the MySQL database.
Search WWH ::
Custom Search