03 - Let us say Hello in EJB: Page 5 of 6

Adding Database Operations using JPA

No as per the problem statement, it is required to store the access log of the web service methods in 2 tables in the database, one for the access [action_log] and the other for the access details [action_log_descripton].

First step, converting our project to JPA project on Eclipse IDE, to do that, go to the “Project Explorer” view and right click on the project icon and select “Configure”, then “Convert to JPA Project”:

            

On the Modify Faceted Project dialog, set checks as follows:

        

Click Next button, on the next screen, select to “Add Connection”, select “MySQL” from the list:

           

Click Next, configure the right driver,

                

Then from the “JAR List” tab, select to load our MYSQL driver in the JBOSS deployments folder

    

Then click OK, Extra Properties controls will appear in the previous window, type our test database properties (connection URL, database, user...etc):

      

Click “Test Connection” to validate your database properties, then click “Finish”, also click “Finish” on the “Modify Faceted Project” dialog. Tthe previous steps will allow Eclipse to connect to our database and fetch the required Tables Metadata to generate the required Entity Beans for our project, and that’s what we will do next.

From the “Project Explorer” view, right click on the project icon and select New, then JPA Entities from Tables.

         

Make sure the “Generate Custom Entities” contains the following values:

        

Also make sure to select the tables “action_log” and “action_log_description”, then click “Next” 3 times till the “Customize Individual Entities” screen appears. Select “IDENTITY” from the Key Generator list and then click “Finish”.

   

Now the package explorer view will contain extra 2 classes in our com.test.hello package, “ActionLog” and “ActionLogDescription”.

          

Like us on Facebook