Presentation is loading. Please wait.

Presentation is loading. Please wait.

Knowledge Byte In this section, you will learn about:

Similar presentations


Presentation on theme: "Knowledge Byte In this section, you will learn about:"— Presentation transcript:

1 Knowledge Byte In this section, you will learn about:
Cascading deletes in entity beans Undefined primary key in entity bean Collaborate

2 Cascading Deletes in Entity Beans
When you invoke the remove() method of a CMP entity bean’s EJB object, the container calls the corresponding ejbRemove() method of the bean implementation class. The ejbRemove() method is responsible for deleting data associated with the bean instance. EJB container first removes a CMP entity bean from various relationships and then deletes the bean and its associated data. You can delete an entity bean and the beans related to it, simultaneously. This involves initializing a series of deletions, starting with the specified CMP entity bean. The deletion continues till all the related entity beans have also been successfully removed. This technique is called cascading delete. Cascading delete is performed for one-to-one and one-to-many relationships between the entity beans. You can use the cascading delete technique when the other end of relationship has multiplicity 1. Collaborate

3 Cascading Deletes in Entity Beans (Contd.)
The cascading delete cannot be implemented for *-* relationships. This is because in case of many-to-many relationships the beans are not related exclusively to each other. You perform the cascading delete operations by declaring the <cascade-delete/> tag in the <ejb-relationship-role> tag of the deployment descriptor of a CMP entity bean. Collaborate

4 Undefined Primary Key in Entity Beans
You can define the primary key of a CMP entity bean at the time of its deployment. This technique is used when you do not know which field needs to be declared as a primary key at the time of coding an enterprise bean. Using this technique, you can specify primary key of the enterprise bean at deployment time. As a result, you can declare the primary key according to the type of database on which the bean is being deployed. The argument type of the findByPrimaryKey() method is declared as java.lang.Object when you declare primary key of an entity bean at deployment time. You need to declare the type of primary key class as java.lang.Object in the deployment descriptor. You also need to avoid accessing the primary key in the CMP entity bean methods because the primary key is only defined at deployment time. Collaborate

5 From the Expert’s Desk In this section, you will learn:
Best Practice on: Tuning Entity Beans Tips and Tricks on: Lazy Loading of Entity Bean References When to Use Entity Beans FAQs on CMP and EJB-QL Collaborate

6 Best Practices Tuning Entity Beans
You can optimize the performance of entity beans by using the following techniques: Using setEntityContext() as cache Committing data after completing a transaction Specifying entity beans instance cache size Using connection pool Collaborate

7 Tips and Tricks Lazy Loading of Entity Bean References Lazy loading:
Refers to the process of delaying the loading of an entity bean’s related beans until the entity bean references them. Provides minimal overhead because it loads a related entity bean only when it is required Is performed by the bean provider in BMP by providing code for it. Is managed by EJB container in CMP beans. However, in CMP you need to enable this feature in the container in order to use it. Collaborate

8 Tips and Tricks When to Use Entity Beans
The following techniques are used to store the data of an EJB application, and make it persistent: Using session beans with JDBC Using entity beans Collaborate

9 Parameter for Comparison Session beans with JDBC
Tips and Tricks When to Use Entity Beans (Contd.) The following table compares the two types of persistence implementations in EJB applications: Parameter for Comparison Session beans with JDBC Entity Beans Control In session beans, bean provider has control over the connectivity because the code for connectivity is written and managed by the bean provider himself. In entity beans, EJB container manages the connectivity. The bean provider does not have much control over the connectivity and database access. Collaborate

10 Parameter for Comparison Session beans with JDBC
Tips and Tricks When to Use Entity Beans (Contd.) Comparison between the two types of persistence implementations: (Contd.) Parameter for Comparison Session beans with JDBC Comparison Procedural versus object-oriented Session beans perform business operations and return the data as result sets that use the procedural approach. Entity beans use the object-oriented approach and are used to represent the Java objects that can support encapsulation and relationships. Caching Session beans represent only the business operations and they cannot be used for caching the data. The entity beans represent the data in the database. Therefore, the caching of data can be performed for the entity beans. Collaborate

11 Parameter for Comparison Session beans with JDBC
Tips and Tricks When to Use Entity Beans (Contd.) Comparison between the two types of persistence implementations: (Contd.) Parameter for Comparison Session beans with JDBC Comparison Migration Session beans use directly or slightly modified SQL code for JDBC connectivity and database operations. Entity beans use the object-oriented approach and they require modifications in SQL code to implement the connectivity. Development time In case of session beans, you need to write the JDBC code for database connectivity and operations. In CMP entity beans, the code for database operations and connectivity is easily created and the development time is faster than the session beans with JDBC. Collaborate

12 FAQs What are the advantages of CMP entity beans as compared to BMP entity beans? CMP entity beans have the following advantages as compared to BMP entity beans: CMP beans are easier to write because you do not write the JDBC code. As a result, you can concentrate on implementing the business logic of application. CMP beans are more portable than BMP entity beans as BMP entity beans contain database-specific connectivity code. CMP beans provide an easier and simpler way to define the various relationships with other entity beans. You can specify and select the relationships in the GUI of the deployment tool. In a BMP entity bean, you have to write the code to implement and manage the relationships. Collaborate

13 FAQs (Contd.) What are the finder methods in EJB?
The finder methods, declared in the home interface of an enterprise bean, are used by the clients to locate the entity beans. The finder methods are declared as starting with findBy prefix. The argument of a finder method is the field value based on which the entity bean object will be retrieved. The example of the finder methods are findByPrimaryKey() and findByName(). You need to import which interface while creating a CMP bean? You need to import the javax.ejb.EntityBean interface. Collaborate

14 FAQs (Contd.) What are the three main clauses of an EJB-QL query where path expressions can appear? The three clauses are, SELECT, FROM, and WHERE. What are the three types of literals used in EJB-QL? The three types of literals used in EJB QL are, string, numeric, and boolean. Collaborate

15 Challenge In CMP entity beans, the ____________ manages the persistence of the enterprise bean. The _____________ method is used to release the resources held by entity bean instance before the bean instance is sent to the Passivate stage. The __________ tag in the deployment descriptor specifies the type of persistence in entity beans. The __________ path expression is used to find whether an expression’s value falls within the specified range or not. The instantiated and unused instances of an enterprise bean are stored in _____________. Collaborate

16 Challenge (Contd.) The method(s) that make(s) an entity bean instance eligible for garbage collection is(are): ejbRemove() unsetEntityContext() finalize() a.      Only A is true b.      Both, B and C, are true c.      Only C is true d Both, A and C, are true Collaborate

17 Challenge (Contd.) Who is responsible for providing the tools for reading and importing the information contained in the deployment descriptor and implementing the tasks of a container: Bean Provider Application Assembler Container Provider End User Collaborate

18 Solutions to Challenge
EJB container ejbPassivate() <persistence-type> BETWEEN Shared pool c. Only C is true c. Container Provider Collaborate


Download ppt "Knowledge Byte In this section, you will learn about:"

Similar presentations


Ads by Google