CMR issue when using findByPrimaryKey
si_hutch Jul 3, 2002 11:55 AMHi,
EJB 2.0
Jboss 3.0
I am fairly new to EJBs so forgive me if this is a ridiculous question.
I am trying to code a One-To-Many Bidirectional Relationship between two entity beans.
User is the One side of the relationship and Calls the Many side.
I need to create calls Remotely and so have coded a Session bean to handle the creation
of calls.
The following code snippet, which I used for testing creates a new user and then a new call for that user
the CMR works perfectly well and the foriegn key is stored in the Calls db Table
public void newCall(String userName, String shortDescription)
throws RemoteException {
Context context = new InitialContext();
//Create a test user
UserLocalHome userHome = (UserLocalHome) context.lookup("local/UserBean");
UserLocal userLocal = userHome.create(userName);
//Create a test call for the user by passing in the Local interface
CallLocalHome callHome = (CallLocalHome)context.lookup("local/CallBean");
CallLocal call = callHome.create(shortDescription,userLocal);
.......
}
However what I actually want to be able to do is to Simply provide the Primary key of an
existing user to the method, look up the Local interface and then create the call for the User.
I have used the following code in the same session bean as the code above.
public void newCall(Integer userId, String shortDescription)
throws RemoteException {
Context context = new InitialContext();
//Get UserLocal interface from Primary key
UserLocalHome userHome = (UserLocalHome)context.lookup("local/UserBean");
UserLocal userLocal = (UserLocal)userHome.findByPrimaryKey(userId);
//Create a test call for the user by passing in the Local interface
CallLocalHome callHome = (CallLocalHome)context.lookup("local/CallBean");
CallLocal call = callHome.create(shortDescription,userLocal);
.......
}
The following is the Jboss console output after this code runs
15:49:51,909 DEBUG [CallBean] Create: pk=9
15:49:51,909 DEBUG [CallBean] Executing SQL: SELECT COUNT(*) FROM CALLS WHERE CALL_ID=?
15:49:52,009 DEBUG [CallBean] Executing SQL: INSERT INTO CALLS (CALL_ID, DATE_CR
EATED, SHORT_DESCRIPTION, LONG_DESCRIPTION, PRIORITY, user_Id) VALUES (?, ?, ?,
?, ?, ?)
15:49:52,109 DEBUG [CallBean] Rows affected = 1
15:49:52,109 DEBUG [UserBean] Executing SQL: SELECT CALL_ID FROM CALLS WHERE (us
er_Id=?)
15:49:52,119 ERROR [LogInterceptor] TransactionRolledbackException, causedBy:
java.sql.SQLException: Table not found: CALLS in statement [SELECT CALL_ID FROM
CALLS WHERE (user_Id=42)]
at org.hsqldb.Trace.getError(Trace.java:180)
at org.hsqldb.Result.(Result.java:175)
at org.hsqldb.jdbcConnection.executeHSQL(jdbcConnection.java:907)
at org.hsqldb.jdbcConnection.execute(jdbcConnection.java:718)
at org.hsqldb.jdbcStatement.fetchResult(jdbcStatement.java:686)
at org.hsqldb.jdbcStatement.executeQuery(jdbcStatement.java:68)
at org.hsqldb.jdbcPreparedStatement.executeQuery(jdbcPreparedStatement.j
ava:133)
This seems a little strange as the output shows the INSERT is successful but the following
SELECT statement fails.
My remote client also catches the following exception
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: Error in addRelation
I am little confused as both snippets above are passing the UserLocal interface to the same method
Can anybody shed any light on this for me
Si