• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Container managed Entity Beans

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to have a business method which have database calls to access and update some other related tables, in a CMP entity bean.
Performance wise, which design will be better, either a CMP bean with this type of business methods or BMP entity beans?
thanks in adv
Joshy Joy
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Container-managed persistence: Here, the EJB container is responsible for saving the state of the Entity Bean. Since it is container-managed, the implementation is independent of the data source. However, all container-managed fields need to be specified in the Deployment Descriptor for the persistence to be automatically handled by the container.
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is it possible to have a business method which have database calls to access and update some other related tables, in a CMP entity bean.
Performance wise, which design will be better, either a CMP bean with this type of business methods or BMP entity beans?


The question you posted has to parts to it. The first is that when you want to access other tables which are not entity beans or the need was not there to make them entity beans then what should one do. Is this proper as per design/performance. The answer is that you have no other option but to undertake a JNDI lookup for a datasource and update that specific table.
The other question you posted that design/performance wise what type of bean should this be. Should it be a BMP or a CMP. The Answer is that an entity Bean must be a CMP always until and unless it can be justified that a BMP is required
You require a BMP only when (As given by Weblogic Documentation)
Possible scenarios where you may need bean-managed transactions are:
You must define multiple transactions from within a single method call. WebLogic Server demarcates transactions on a per-method basis; if you require multiple transactions in a single method call, you must use bean-managed transactions.
Note: However, keep in mind that if your EJBs use multiple transactions in a single method call, it is still better to break the method into multiple methods, with each one having its own container-managed transaction.
A single transaction must "span" multiple EJB method calls. For example, one method begins a transaction, and another method commits or rolls back the transaction. In general, this practice should be avoided where possible since it requires detailed information about the workings of the EJB object. If it is required, you must use bean-managed transaction coordination, and you must coordinate client calls to the respective methods.

[This message has been edited by Rahul Mahindrakar (edited September 11, 2001).]
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
u can use any code inside your CMP... as long as it does not change the state of that very bean... I see no reason to go for a CMP and then writing JDBC in your business methods (i dont even to call it a design)... in case the the bean state changes as a result of your jdbc call, you have to make sure that the instance variable are also updated... adn the container wud again call ejbStore (so extra jdbc call).. i dont understand what resources are you trying to save here...

Originally posted by Joshy Joy:
Is it possible to have a business method which have database calls to access and update some other related tables, in a CMP entity bean.
Performance wise, which design will be better, either a CMP bean with this type of business methods or BMP entity beans?
thanks in adv
Joshy Joy


 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Performance-wise" you'd be better off avoiding EJBs altogether and doing everything yourself in a JSP or servlet. Architecturally (and maintenance-wise), you'd be cleaner to have a session EJB co-ordinating the database functionality and making entity beans for both the primary and the "side-effect"ed database tables.
 
Author
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
It is very difficult to give a general answer which is better in terms of performance, CMP or BMP. A lot depends of the application server and the DBMS you are using. Particularly application server can provide several optimizations to speed up the CMP entity beans.
EJB 1.1 CMP model did not provide many opportunities to app server vendors to do the optimizations. It made it very difficult to check for state changes and made it almost impossible to do partial state updates. CMP 2.0 model is much better; however we will have to wait for mature app servers that will actually implement all possible optimizations.
I would encourage using CMP if possible, because you will have less code to write and will benefit from future app server optimizations. However it this turns out to be too slow you will have to go with BMP. Using a good app server, CMP beans should perform faster than average written BMPs.
Hope this helps :-),
Matjaz

------------------
Matjaz Juric
Author of Professional EJB
 
Joshy Joy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for the prompt and informative response. Sorry that I forgot to mention the environment that I am working on
I am using IBM WAS 3.5 and DB2 7.1
Also I am using IBM visual age for Java for developement.
In my application I have four related tables
I have three options
option 1. create 4 CMP beans and look up each and access/update tables and beans
option 2. create a single CMP bean (for main table) and have a business method which accesses/updates the other tables thru storedprocs/ queries
option 3. have a single BMP bean and manage all the database activities
From all the answers I got What I understood is that the "option 1" is better. Hope you all will give your comments
Thanks once again
Joshy Joy
 
And inside of my fortune cookie was this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic