HOME

TheInfoList



OR:

Composite entity is a
Java EE Jakarta EE, formerly Java Platform, Enterprise Edition (Java EE) and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web serv ...
Software design pattern In software engineering, a software design pattern or design pattern is a general, reusable solution to a commonly occurring problem in many contexts in software design. A design pattern is not a rigid structure to be transplanted directly into s ...
and it is used to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine-grained entity beans, and also a composite entity bean represents a graph of objects.


Structure

There are a number of strategies to implement composite entity pattern. This pattern mainly composites of composite entity, coarse-grained object, and dependent objects.


Composite entity component

Composite entity is the coarse-grained entity bean which may be the coarse-grained object, or may contain a reference to the coarse-grained object.


Coarse-grained object

A coarse-grained object is an object with its own life cycle manages its own relationships to other objects. It can be an object contained in the composite entity, or, composite entity itself can be the coarse-grained object which holds dependent objects.


Dependent objects

It is an object, which can contain other dependent objects (there may be a tree of objects within the composite entity), that depends on the coarse-grained object and has its life cycle managed by the coarse-grained object.


Consequences

According to Oracle description of the pattern, consequences include eliminating inter-entity relationships, improving manageability by reducing entity beans, improving network performance, reducing database schema dependency, increasing object granularity, facilitating composite transfer object creation and overhead of multi-level dependent object graphs.


Drawbacks

The fatal drawback is the requirement of bean-managed persistent (BMP)
bean A bean is the seed of some plants in the legume family (Fabaceae) used as a vegetable for human consumption or animal feed. The seeds are often preserved through drying (a ''pulse''), but fresh beans are also sold. Dried beans are traditi ...
. This involves more work for developers, and create some problems as follows: * materializing all the data in a coarse-grained entity whenever it is accessed, is unacceptably expensive * In
Java Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, implementation of the ejbStore() method needs to be smart enough to avoid issuing all the updates required to persist the entire state of the object, unless the data has changed in all the persistent objects. Composite entity pattern can only be implemented using BMP or by adding more hand-coded persistence logic to container managed persistence (CMP)
beans A bean is the seed of some plants in the legume family (Fabaceae) used as a vegetable for human consumption or animal feed. The seeds are often preserved through drying (a ''pulse''), but fresh beans are also sold. Dried beans are tradition ...
. These both approaches reduce the maintainability.


Sample code

Sample code for a Professional Service Automation application (PSA) in which the resource object is implemented via composite entity pattern, may look like as follows (entity implements coarse-grained object): package corepatterns.apps.psa.ejb; import corepatterns.apps.psa.core.*; import corepatterns.apps.psa.dao.*; import java.sql.*; import javax.sql.*; import java.util.*; import javax.ejb.*; import javax.naming.*; public class ResourceEntity implements EntityBean


See also

*
Data transfer object In the field of programming a data transfer object (DTOMSDN (2010). Data Transfer Object. Microsoft MSDN Library. Retrieved from https://msdn.microsoft.com/en-us/library/ms978717.aspx.Fowler, Martin (2010). Data Transfer Object. Patterns of Enterpr ...


References

{{Design Patterns patterns Software design patterns Articles with example Java code