Java Reference
In-Depth Information
in the EJB 3. x specification. JPA supports POJO persistence with annotation-based con-
figuration. More important, JPA entities run outside the EJB container and are easily
testable.
The eInsure development team soon realized that search operations that returned
large lists were highly inefficient with entity beans since each object in the search list was
itself an entity bean. So, accessing a property in this entity bean resulted in a network trip
and in the marshaling and unmarshaling of the data. The team soon switched over to a
straight JDBC approach. The JDBC API was being used directly from the session beans to
execute SQL queries, as shown in Listing 5-1.
Listing 5-1. UnderwritingRemoteBean.java
public class UnderwritingRemoteBean implements SessionBean{
public List listPolicyByProductAndAgeLevel(String productCd, int age) throws
RemoteException {
String SQL = "SELECT POLICY_ID,PRODUCT_CODE, NAME, AGE FROM T_POLICY_DETAILS
WHERE PRODUCT_CODE = ? AND AGE > ? ";
List policyList = new ArrayList();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try{
pstmt = conn.prepareStatement(SQL);
pstmt.setString(0, productCd);
pstmt.setInt(1, age);
rs = pstmt.executeQuery();
while(rs.next()){
policyList.add(new PolicyDetail(rs.getInt("POLICY_ID"),
rs.getString("NAME")
,rs.getString("NAME"),rs.getInt("AGE")));
}
}
catch(SQLException sqlex){
throw new RuntimeException(sqlex);
}
finally{
 
Search WWH ::




Custom Search