W R I T E A N D D E P L O Y J 2 E E A P P L I C A T I O N S
{
DataSource lDataSource = getDataSource();
Connection lConnection = null;
PreparedStatement lStatement = null;
try {
lConnection = lDataSource.getConnection();
lStatement = lConnection.prepareStatement(
"SELECT Id, First_Name, Last_Name FROM TestEntity WHERE id = ?"
);
int lId = ( (TestBMPEntityPK) mContext.getPrimaryKey() ).id;
lStatement.setInt( 1, lId );
ResultSet lResult = lStatement.executeQuery();
lResult.next();
setId( lResult.getInt( 1 ) );
setFirstName( lResult.getString( 2 ) );
setLastName( lResult.getString( 3 ) );
// Because this method used the attribute setter method
// the bean is automatically marked as dirty. Therefore
// reverse this here because it is obviosly not true
makeClean();
}
catch ( SQLException se ) {
throw new EJBException( "Could not read record from DB: " + se.getMessage() );
}
finally {
if( lStatement != null ) {
try {
lStatement.close();
}
catch( Exception e ) {}
}
if( lConnection != null ) {
try {
lConnection.close();
}
catch( Exception e ) {}
}
}
}
Container Managed Persistence (CMP)
This type of Entity Beans uses an Object Relational Mapper (O/R Mapper) to store data on
persistence store and recreated them. Most O/R Mappers supports various databases and
allows a bean developer to create Entity Beans that are not only server vendor neutral but
also database vendor neutral.
Because the CMP implementation is so important and became somewhat complex this book
explain it in its own chapter 7, so please have a look there.
46
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved