コンテナがデータベースからデータを削除するときに呼び出すメソッドです。
Entity Beanを呼び出すEJBアプリケーションがremoveメソッドを呼び出すと、コンテナはremoveメソッドに対応するejbRemoveメソッドを呼び出します。
記述する処理の概要
ejbRemoveメソッドには、以下の処理を記述します。
該当するインスタンスのプライマリキーオブジェクトをキーにして、データベースからレコードを削除(DELETE)する処理
ejbRemoveメソッドの規約
ejbRemoveメソッドは以下の規約を満たしていなければなりません。
メソッドはpublicとして定義されていなければなりません。
返却値はvoidでなければなりません。
throws句には以下の例外を定義することができます。
任意のEJBアプリケーション固有の例外
javax.ejb.EJBException
javax.ejb.RemoveException
記述例
public void ejbRemove() throws javax.ejb.EJBException, javax.ejb.RemoveException { Connection connection = null; PreparedStatement psDelete = null; SampleBeanPrimaryKey pk = null; int rows = 0; try { // レコードの削除 connection = dataSource.getConnection(); psDelete = connection.prepareStatement("DELETE FROM SAMPLESCM.SAMPLETBL WHERE ID = ?"); pk = (SampleBeanPrimaryKey)context.getPrimaryKey(); psDelete.setObject(1,pk.code); rows = psDelete.executeUpdate(); } catch(SQLException e) { throw new EJBException(e.getMessage()); } finally { try { if (psDelete != null) psDelete.close(); if (connection != null) connection.close(); } catch(Exception e) {} } if (rows != 1) throw new RemoveException("ejbRemove failed"); }