Building a web application using hibernate, spring and gwt.
This time we will show how to create and cofigure an application that will use hibernate , spring and gwt.
I will use HR sample database that comes with OracleXE.
First , you have to create a GWT project (you can follow the steps for that on https://developers.google.com/web-toolkit/)
After you have the project created you need to create a tree of packages like that:
Open HumanResources.gwt.xml and add the following line :
By doing that you tell gwt to include model package and all dependent packages into gwt compilation
Now we can start configuring spring and hibernate.
to configure spring first you have to add the following lines on web.xml
This will allow spring context to start doing its business.
The you will have to create a field called "app-config.xml" in which you will define the settings for spring and hibernate.
Over this app-config file first configure the properties as follows
You will have to create another file called configuration.properties in which you will define the values of the properties that you will use on you xml (this will also apply for included xmls)
Next you need to configure the component scan as follows
The lines above will tell spring to scan the annotations defined on classes of package com.model.services and com.hr.model.daos
The last step for this file is to include the xml for configuring hibernate:
By doing that you will tell spring to read also the contents of db-config.xml.
Now is time to configure db-config.xml, this file contains all the configuration that hibernate will use:
Remember the file called configuration.properties? Well, here is where we will use the properties defined on it.
After defining the DS we proceed to set-up hibernate session factory
Here you define the packages to scan. These will tell hibernate where to look for annotated classes in this example hibernate will look on "com.hr.model.beans".
You will also use the values defined on configuration.properties to tell hibernate which dialect to use. The database of the example is oracle in my case I use "org.hibernate.dialect.Oracle10gDialect"
Finally we will define the TransaciontManager and add the sessionFactory we've created and also tell spring that you will define the transactional behaviour by using annotations:
That's it. We finished configuring the project, now we can start coding.
On the next post I will explain step for step the coding for this tutorial.
This time we will show how to create and cofigure an application that will use hibernate , spring and gwt.
I will use HR sample database that comes with OracleXE.
First , you have to create a GWT project (you can follow the steps for that on https://developers.google.com/web-toolkit/)
After you have the project created you need to create a tree of packages like that:
Open HumanResources.gwt.xml and add the following line :
Now we can start configuring spring and hibernate.
to configure spring first you have to add the following lines on web.xml
This will allow spring context to start doing its business.
The you will have to create a field called "app-config.xml" in which you will define the settings for spring and hibernate.
Over this app-config file first configure the properties as follows
You will have to create another file called configuration.properties in which you will define the values of the properties that you will use on you xml (this will also apply for included xmls)
Next you need to configure the component scan as follows
The lines above will tell spring to scan the annotations defined on classes of package com.model.services and com.hr.model.daos
The last step for this file is to include the xml for configuring hibernate:
By doing that you will tell spring to read also the contents of db-config.xml.
Now is time to configure db-config.xml, this file contains all the configuration that hibernate will use:
Remember the file called configuration.properties? Well, here is where we will use the properties defined on it.
After defining the DS we proceed to set-up hibernate session factory
Here you define the packages to scan. These will tell hibernate where to look for annotated classes in this example hibernate will look on "com.hr.model.beans".
You will also use the values defined on configuration.properties to tell hibernate which dialect to use. The database of the example is oracle in my case I use "org.hibernate.dialect.Oracle10gDialect"
Finally we will define the TransaciontManager and add the sessionFactory we've created and also tell spring that you will define the transactional behaviour by using annotations:
That's it. We finished configuring the project, now we can start coding.
On the next post I will explain step for step the coding for this tutorial.
Comments