June 21, 2008, 11:36 a.m.
posted by hashspark
Exercise 6.2: @IdClassThis exercise shows you an example of using @javax.persistence.IdClass to map a primary key class to the database. Start Up JBossIf you already have JBoss running, there is no reason to restart it. Otherwise, start it up as instructed in Workbook 1. Initialize the DatabaseThe database tables will be created when Exercise 6.2 is deployed to JBoss. If you have problems running this example, shut down JBoss and run the clean.db Ant task. Build and Deploy the Example ProgramsPerform the following steps:
As in the last exercise, titan.jar is rebuilt, copied to the JBoss deploy directory, and redeployed by the application server. Examine the Example FilesThe Customer entity code was a cut-and-paste from the @IdClass section of Chapter 6, so it needs no further explanation. TRavelAgentBean again acts as a simple data access object, wrapping invocations around the EntityManager instance injected into this EJB. The Client application simply allocates a Customer entity and then calls createCustomer( ) and findCustomer( ) on TRavelAgentBean to insert and find the Customer in the database. Run the ClientRun the Client application by invoking ant run.client at the command prompt. Remember to set your JBOSS_HOME and PATH environment variables. This is the output:
run.client:
[java] Bill
[java] Burke
[java] 9999999
|
- Comment