Click on the images to view them full size!
Step 5 - Configure JAAS Authentication
The username and password to authenticate the data source needs to be entered as a JAAS entry in the Server configuration.
Double click on 'TestServer' in the Server Configuration view and clikc on the Security tab in the window opened.
Click the Add button against 'JAAS Authentication Entries' add a name for the Authentication Entry, Database Username, Password etc, and click OK.
Step 6 - Configure the Oracle DataSource
In the Server Configuration view click the DataSource tab in the window opened.
In the JDBC Providers List, you will see the CloudScape and DB2 database Drivers added by Default. We need to add Oracle Provider here. Click on the Add button, and select Oracle from the database Type list. Select Oracle JDBC Oci Driver from the 'JDBC Provider Type' list.
Click next and name the new provider as 'Oracle JDBC OCI'. Note that the implementation class is by default selected as oracle.jdbc.pool.OracleConnectionPoolDataSource and the classpath is set to ${ORACLE_JDBC_DRIVER_PATH}/ojdbc14.jar. To make sure that the path points to the right jar, either set the ORACLE_JDBC_DRIVER_PATH to the jdbc/lib folder of your Oracle installation in the Variables tab in the Server Configuration OR manually select the jar from the Oracle installation clicking the 'Add External Jars' button. Click Finish
Now, select the DataSource tab again, and click the Add button against the DataSource defenitions list. In the window opened, select the Database provider we just created(Oracle JDBC OCI) and select the DataSource version as 5.0. Version 4 Datasources can only be used with EJB 1.2 or lesser versions.
Click Next. Here we give a name for the DataSource - EmployeeDS, its JNDI name - jdbc/EmployeeDS, and Component and select the Container Authentication aliases from the drop down. This must be the one we created in Step 5.
Click Finish.
Now, it's time for us to define the datasource properties. Select the DataSource tab again, aand select Oracle OCI Driver in the Providers list, and select EmployeeDS in the DataSource listing. In the Resource Properties list of our DataSource, select the URL property and change the value to your database connection URL (Something like this: jdbc:oracle:oci:@JJDB)
Note : This example uses the Oracle OCI Driver to establish a connection to the Database, which means, there exists a tnsnames.ora file which contains an entry by this name - JJDB and its connection details. Alternatively, you may opt to use the JDBC thin driver, in which case you will have to specify the whole connection parametsrs in the URL string. (Something like this: jdbc:oracle:thin:@MY.DBSERVER.COM:1521:JJ)
We are now done with the Datasource defenition. Click Save All in the file menu to save the Configurations.
Step 7 - Create EJB to RDB Mapping
Right-Click the EmployeeEJB Project and select Generate->EJB to RDB Mapping. Select 'Create a New Backend Folder' and click Next. In the next window, select 'Top Down' approach.
In the next window, Select Oracle9i in Target Database Type and enter the Database name (JJ in this case). The schema name can be left as such as NULLID. When you click finish, the EJB<->RDB mapping gets created. You will see that the fields of the EmployeeEntity bean are already mapped to corresponding fields of the Database Table.
You might have to change these default mappings. For instance, in my case the table name in the persistance schema is by default taken as EMPLOYEEENTITY, whereas my actual table name is EMPLOYEES. To change this, right click the table name and select 'Open Table Editor'.
In the window opened, change the table name to your actual table name.
If you want t o remove or re-assign these dafault field mappings, thois can be done in the Mapping Outline view, as shown below.
You may drag and drop fields from the Enterprise Bean field list to the Table fiels to create mappings again.
Go to : Part 1Part 2Part 3Part 4Part 5Part 6
No comments:
Post a Comment