chapter 5.
creating a bmp entity bean 【程序编程相关:hibernate高级特性_1】
【推荐阅读:J2EE项目危机【翻译】 -避免这10项】
【扩展信息:JSP中文乱码问题的解决】
this chapter describes how to create a bean managed persistence (bmp) ejb component. we will create two bmp beans, customer and manager, as shown below. the customer bean will be responsible for storing the details of customers of mystore. the manager bean stores details of the manager of mystore. both beans communicate with their respective tables in the database using data access objects (daos) named customerdao and managerdao respectively.
all customers have been assigned a unique customerid for housekeeping purposes in mystore in addition to their username for accessing the services of mystore. similarly the manager of mystore has been assigned a unique managerid.
note : it is the usual practice to access business methods of bmp beans via a session bean, which encapsulates business logic and acts as an interface to further ejb components. in this case customer and manager are accessible via by storeaccess.
this approach comes from a pattern called a session facade, whereby enterprise beans encapsulate business logic and business data and expose their interfaces. the session bean acts as a facade to encapsulate the complexity of interactions with the lower-level beans. the session facade is responsible for managing business objects and provides a uniform business service abstraction to presentation layer clients, thereby hiding the business object implementation in the lower-level beans.
this tutorial uses that pattern for business tier implementation.
tasks :
create a bmp bean named customer under package au.com.tusc.bmp.
create a dao class named customerdaoimpl under package au.com.tusc.dao.
add all attributes/properties to the customerbean, with getter and setter methods for each of the attributes.
add a finder method named ejbfindbyprimarykey with the signature
public customerpk ejbfindbyprimarykey (customerpk pk) throws finderexception
add a finder method named ejbfindbyuserid with the signature
public customerpk ejbfindbyuserid (string userid) throws finderexception
add a business method named getcustomerdata with the signature
public customerdata getcustomerdata()
implement required methods in the customerdaoimpl class.
deploy the customer bean.
add a create method to the storeaccess bean.
public void ejbcreate() throws javax.ejb.createexception
add a business method to the storeaccess bean.
public customerdata getcustomerdata(string userid)
create a test client named sessionbmpclient under package au.com.tusc.client.
run your client and test the bean.
create the customer bmp entity bean :go to package explorer > expand mystore (project) node > select src, right click and a menu will pop up.
on the pop up menu > new > lomboz ejb creation wizard.
enter package name au.com.tusc.bmp, bean name customer and select bean type as bean manged entity > finish.
... 下一页