Bean or Container Managed Persistence

Hi,
I've been reading up on the Sun J2EE tutorial. One of the topics there is bean or container managed persistence. It states that container managed is easier for developers and allows for more portability. The class codes are much smaller compared to bean managed and developers need not worry about database queries.
Can anyone share their experiences on this? Any 'Real World' advantages and disadvantages? Is there a guideline I can follow when to use bean or container managed persistence?
Thanks,
-Ray

That seems like an obvious flaw. So why was it even considered in the
J2EE framework? I mean wouldn't the J2EE architects immediately realize
that? Just doesn't make sense to me why there's even a tutorial or books
for it. What does it suppose to solve then??I know what you mean... again, I think they thought it looked good on paper.
And it gets worse...
Before you use Entity Beans you must be absolutely sure that there will never be another app that accesses the underlying table that doesnt use the EntityBean to do it... For example a C++ App that accesses the tables directly... otherwise you have to set a flag in the App Server that states that basically every time a property on an EntityBean is read the Bean will have to RE-READ the beans state from the database!!
Some things look really good, from an OO perspective, but dont work really well in reality. Sure Entity Beans look really good in the example program in the tutorial, but what happens when you multiply the number of entity beans by 1000, 100,000, or more? Just think of the CPU, and Memory overhead for instantiating all those objects!
There are people out there who believe that using Stored Procedures is a no-no because in their minds it puts "Business Logic" on the database and not the App Server...To this I say... BUNK... Ive seen several instances where by simply moving a set of queries from the App Server to a stored procedure on the database, allowed for a 10-20 times performance gain because of the elimination of network IO. In one instance I saw a query go from 3 hours execution time on the App Server to under 10 minutes on the database... But stored procedures arent OO...
So IMHO before you use EntityBeans at all... be absolutely sure you understand all of the ins-and-outs of doing so.

Similar Messages

  • Container Managed Persistence entity bean relationship fields

    I want to ask something that until now still confuse. Did Relationship fields in Container Managed Persistence entity beans declare , inside Database table or only Persistence fields .
    If Relationship fields not declare inside database table ,how if SQL calls the relationship fields between related entity bean.
    did container handle this task.
    example: I have 2 entity bean with CMP(Container Managed Persistence)version 2.0
    call Player and Team. every entity bean have own relationship fields and persistence fields.
    player has playerId(primary key),name,position,age persistence fields and teams is relationship fields.
    team has teamId(primary key),name,city and players is relationship fields.
    I know that all persistence fields is declare in own database table but how about relationship fields.
    can you tellme, How SQL calls can access relationship fields if relatiosnship fields is not declare in database table.
    I use J2EE RI SDK version 1.3
    and deploytool .
    thank's .

    thank's for your reply .Now I have another problem
    I use J2EE RI from java.sun .I try to follow example in j2eetutorial about CMP Example call RosterApp.ear .
    I dont'change anything code inside RosterApp.ear but when I deploy and runclient command thereis syntax error :
    java.rmi.ServerException: Remote exception occured in server thread :nested exception is java.rmi.ServerException :exception thrown from bean :nested exception is : java.ejb.EJBException :nested exception is :java.sql.SQLException :syntax error or access violation ,message from server: "you have an error in SQL syntax near "
    "leagueBeanTable" WHERE "leagueId" = 'L1' at line 1
    in example ,RosterApp.ear use Cloudscape database ,but I try to use Mysql database for RosterApp.ear ,is there any different syntax SQL from Cloudscape to Mysql .
    if like that ,so I must edit first SQL calls from Cloudscape to MYSQL . I think because relationship fields is for entity beans only ,so how if mysql database want to access foreign key another table because foreign key isn't declare in databse table.
    example : I have 3 entity bean call player, team, league .
    1. PlayerEJB have persistence fields name, position, playerId(primary key), cmr fields is teams
    2. TeamEJB have persistence fields name, city, teamId (primary key) , cmr fields is players and leagues .
    3. LeagueEJB have persistence fields name ,sport, leagueId(primary key), cmr fields is teams
    so table is
    PlayerEJB <--->TeamEJB<--->LeagueEJB
    Player have some finder method call findBySport(String Sport) .
    because Sport is persistence fields for LeagueEJB
    so PlayerEJB must traverse TeamEJB first before LeagueEJB
    EJB QL : SELECT distinct object(p) FROM Player (p) IN (p.teams) AS t
    WHERE t.league.sport = ?1
    I know that Container will translates EJB QL to SQL calls ,but default is only for cloudscape database and I use for MYsql .
    so can you helpme how to query method findBySport(String sport) to Mysql calls .
    thereis no foreign key between table in database table there is only Relationship fields in entity bean.

  • Bean-Managed vs. Container-Managed Persistence

    Hello,
    I would like the real world skinny on bean-managed persistence vs. container-managed persistence. I have heard the bean-managed offers higher scalability and performance, while container-managed offers simplicity but with a cost. Can someone give me some perspective?
    Thanks,
    Rob Miller

    Wrong forum, but I guess if you are new to java it could be argued that anything goes...
    General rule:
    use CMP if you don't have worries about speed or legacy systems.
    use BMP if you need to control the persistence and/or want to connect to legacy host systems. BMP allows you to set up caching and transaction handlers to handle the presistence in a manner more suited to your needs.

  • Container-managed persistence Entity bean

    WE use a container-managed persistence Entity bean. To handle the state synchronization between the object & the database, what must WE do?
    Thanks in Advance

    That's the container's job. You can use the commit option A/B/C to control how the DB and objects are synchronized.
    -Scott
    http://www.swiftradius.com

  • Container-managed persistence application problem

    I worked out a container-manager persistence entity bean application. Everything is fine until I run the client. When I ran the client, I got the following exception from the server side when I turned on "j2ee -verbose":
    "Exception in thread "RequestProcessor[20]" org.omg.CORBA.BAD_PARAM: CourseBean_P
    M_EJBLocalObjectImpl minor code: 1330446342 completed: Maybe
    at com.sun.corba.ee.internal.orbutil.ORBUtility.throwNotSerializableForC
    orba(ORBUtility.java:660)
    at com.sun.corba.ee.internal.iiop.CDROutputStream_1_0.write_abstract_int
    erface(CDROutputStream_1_0.java:631)
    at com.sun.corba.ee.internal.iiop.CDROutputStream.write_abstract_interfa
    ce(CDROutputStream.java:281)
    at com.sun.corba.ee.internal.javax.rmi.CORBA.Util.writeAbstractObject(Ut
    il.java:145)
    at javax.rmi.CORBA.Util.writeAbstractObject(Util.java:128)
    at com.sun.corba.se.internal.io.IIOPOutputStream.writeObjectDelegate(IIO
    POutputStream.java:99)
    at com.sun.corba.se.internal.io.IIOPOutputStream.writeObjectOverride(IIO
    POutputStream.java:106)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:271)
    at java.util.ArrayList.writeObject(ArrayList.java:513)
    at com.sun.corba.se.internal.io.IIOPOutputStream.writeObject(Native Meth
    od)
    at com.sun.corba.se.internal.io.IIOPOutputStream.invokeObjectWriter(IIOP
    OutputStream.java:525)
    at com.sun.corba.se.internal.io.IIOPOutputStream.outputObject(IIOPOutput
    Stream.java:492)
    at com.sun.corba.se.internal.io.IIOPOutputStream.simpleWriteObject(IIOPO
    utputStream.java:125)
    at com.sun.corba.se.internal.io.ValueHandlerImpl.writeValueInternal(Valu
    eHandlerImpl.java:134)
    at com.sun.corba.se.internal.io.ValueHandlerImpl.writeValue(ValueHandler
    Impl.java:114)
    at com.sun.corba.ee.internal.iiop.CDROutputStream_1_0.write_value(CDROut
    putStream_1_0.java:1049)
    at com.sun.corba.ee.internal.iiop.CDROutputStream_1_0.write_value(CDROut
    putStream_1_0.java:638)
    at com.sun.corba.ee.internal.iiop.CDROutputStream.write_value(CDROutputS
    tream.java:268)
    at _RegisterBean_EJBObjectImpl_Tie._invoke(Unknown Source)
    at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(Ge
    nericPOAServerSC.java:519)
    at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(Gen
    ericPOAServerSC.java:204)
    at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAS
    erverSC.java:112)
    at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:273)
    at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProces
    sor.java:84)
    at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadP
    ool.java:99)
    Anybody has any insight in this. I checked the appliation using the verification tool, it shows no problem at all. I am really out of idea!
    Thanks a lot!

    send me your contact info and i think i can help.
    my email is : [email protected]
    In addition I believe ssniazi is in violation of the conduct code of this website because ssniazi is requesting information which will be used by a business entity without telling the users that it will be used in that way. And I expect that Oracle itself would frown on such activities.
    2.3 You agree that You will not use the Website to:...(g) collect or store personal data about other users unless specifically authorized by such users.

  • Extreamly slow container managed persistence

    Hi.
    We perform the following procedure:
    1. We invoke a finder method on a container managed bean
    2. Then we traverse the enumeration of beans returned and invoke a getter
    method to get their properties.
    The finder finishes really fast, but then traversing the enumeration takes
    about 1 second per entity bean.
    Any suggestions?
    Giora Katz-Lichtenstein

    Hi,
    When you're iterating through your collection or enumeration of primary
    keys, each method call is going to the database to retrieve the row
    associated with that primary key. I'll bet the issue is with the calls to
    the db or whatever persistent store you're using.
    Steve...
    Giora <[email protected]> wrote in message
    news:82kolv$192$[email protected]..
    Hi.
    We perform the following procedure:
    1. We invoke a finder method on a container managed bean
    2. Then we traverse the enumeration of beans returned and invoke agetter
    method to get their properties.
    The finder finishes really fast, but then traversing the enumeration takes
    about 1 second per entity bean.
    Any suggestions?
    Giora Katz-Lichtenstein

  • 1-many CMP2.0 Container Managed Persistence

    Sorry for posting this again, but there did not seem to be any replies.
    I have noticed a very strange phenomena in 1-many container managed relationships in the J2EESDK1.3.
    In 1-many Container Managed Relationships, the J2SDKEE1.3 actually generates 3 tables rather than 2. The first table is the 1 side table. The second table is the many side table. The third table is a relation table joining the 1 side table and many side table. This relation table has 2 fields, one is the primary key of the many side table (this field becomes the primary key of the relation table) and the other field is the primary key of the one side table.
    This generation of a new table for 1-many relationships is giving me a headache because these tables now form a (0 or 1) - many relationship now.
    Is this defined as part of the EJB2.0 spec or is this a J2SDKEE1.3 dependant feature?

    I'm afraid I can't give you an exact answer to this question, but it seems to me that this is a work-around in order not to create the relationshis in the DB.
    I have noticed this behaviour as well, only I have found another problem with it. The relationship table doesn't seem to survive an undeploy or server restart. Do you have the same problem?
    I think that maybe a commercial application server with a database for which it has been optimized will not show this behaviour, but will define the relationship as meta-data in the DB.

  • Accessing collection field in container managed persistence bean

    Hello!
    How can i get 1:m relatioship, collection fields value?
    What is the purpose of ejbSelect-method, in bean business class?

    Please ask your EJB questions within the Enterprise JavaBeans section of this forum.
    The ejbSelect Method is a query method (like the finder mehtod) but it is not directly exposed to the client in the home interfacce or component interface. Rather, ejbSelect() is used internally within an entity bean as a helper method to accesss a storage. ejbSelect() is useful when you have entity beans in relationships with external data, such as other entity beans.
    look at http://www.theserverside.com/articles/content/ApplyingEJB/matena8.pdf for an example

  • Container managed persistence

    Hi!
    I'm trying to figure out how CMP works with IPlanet but haven't found any
    examples. I would need to know where to define the table names that my
    entity beans use?
    Sebastian

    Hi Seb,
    Please find the attached file .....will help u
    Ananthram
    "Sebastian Lofhjelm" wrote:
    Hi!
    I'm trying to figure out how CMP works with IPlanet but haven't found any
    examples. I would need to know where to define the table names that my
    entity beans use?
    Sebastian

  • How to add a finder method in the container manager Bean in the weblogic6.1

    in the environment jbuilder6 andweblogic6.1,use container manager entity Bean,it can automatic generate the findAll() method,I want to add a new method to find an element in the home interface,such as findByName(),name is a element of a table of the database.in the weblogic-cmp-rdbms-jar.xml,this is part of the fiile:
    <finder>
    <finder-name>findAll</finder-name>
    <finder-query><![CDATA[ (= 1 1) ]]></finder-query>
    </finder>
    <finder>
    <finder-name>findByName</finder-name>
    <finder-param>java.lang.String</finder-param>
    <finder-query><![CDATA[ (=name $name) ]]></finder-query>
    </finder>
    It can successfully compile the findAll(),but it is wrong when compile the findByName(),as follows
    "www.ejbgrpx": Method Name: findByName
    "www.ejbgrpx": Invalid specifications for a WebLogic RDBMS CMP EJB.
    "www.ejbgrpx": ERROR: Error from ejbc: weblogic.ejb20.cmp11.rdbms.finders.IllegalExpressionException:
    "www.ejbgrpx": While trying to process Finder
    "www.ejbgrpx": Parameter Types: (java.lang.String)
    "www.ejbgrpx": WebLogic Query: (= name $name)
    "www.ejbgrpx": Finder Expressions: ()
    "www.ejbgrpx": Could not parse WLQL expression: (= name $name) null
    "www.ejbgrpx": ERROR: ejbc found errors
    thank you

    The finder methods that you are referring to are only simple finder methods. If you would like to add specialized finder methods, you can make your entity bean with bean managed persistence and not container managed. If you are using EJB 2.0, your entity bean with container managed persistence can use EJB QL for finder methods. You can search for this topic and/or download the EJB 2.0 specifications
    Hope this helps

  • Finder method in container-managed entity bean

    Finder method of a container entity bean is taking the primary key class object of another entity bean. How to map this in the xml descriptor file weblogic-cmp-rdbms.xml for this type of beans.
    I am trying to deploy the jasmine computer store of Mastering EJB by EdRoman.
    I couldn't write the deployment file weblogic-cmp-rdbms.xml for Order Entity bean which uses CustomerPK as an argument in its finder method.
    Please tell me how to write this. I am trying on weblogic 5.1
    Thanx in advance
    Srivatsa

    hello,
    in container managed persistence, you specify on your xml file the name of your table. so the primary key you want to use have to be a foreign key in your table. otherwise i don't think that you can use a container managed persistence.
    Najib.

  • Container Managed Entity Beans and Client Identifier in Oracle

    Is it possible to use Container Managed Entity Beans (EJB with CMP)
    in a way that the Oracle database sessions still know the
    individual Client Identifiers of the actual users
    (not just the Identifier of the proxy user defined in the
    Connection Pool)?
    If Yes: How?
    If No: The consequence would be that the
    technologies EJB with CMP cannot be user together with
    Oracle Virtual Private Databases (VPN) because VPN requires
    some kind of Client Identifier.
    I am grateful for any hint.
    Regards,
    Martin Siepmann
    +49 (0)163 / 7765328

    Not quite an auto-incrementing PK, but it is managed by the container. the following is from the turorial
    Generating Primary Key Values
    For some entity beans, the value of a primary key has a meaning for the business entity. For example, in an entity bean that represents a phone call to a support center, the primary key might include a time stamp that indicates when the call was received. But for other beans, the key's value is arbitrary--provided that it's unique. With container-managed persistence, these key values can be generated automatically by the EJB container. To take advantage of this feature, an entity bean must meet these requirements:
    * In the deployment descriptor, the primary key class is defined as a java.lang.Object. The primary key field is not specified.
    * In the home interface, the argument of the findByPrimaryKey method must be a java.lang.Object.
    * In the entity bean class, the return type of the ejbCreate method must be a java.lang.Object.
    In these entity beans, the primary key values are in an internal field that only the EJB container can access. You cannot associate the primary key with a persistent field or any other instance variable. However, you can fetch the bean's primary key by invoking the getPrimaryKey method, and you can locate the bean by invoking its findByPrimaryKey method.
    Maybe that is good enough
    christina

  • Container-managed / bean-managed transaction demarcation

    I am trying to make sure I understand container-managed and bean-managed transaction demarcation and in particular where you have one bean calling another bean. What happens where one of the beans has container-managed transaction demarcation and the other bean-managed transaction demarcation. In fact the initial question to ask is, is this allowed?
    Lets use an application scenario to illustrate the issue. The application has a payment transaction. Payments can be received in one of two ways:
    1. As a payment at a branch where the individual payment is processed on a client application and resulting in the processing of a single payment transaction.
    2. As a batch of payments received from a bank containing, potentially, thousands of payment transactions.
    The proposed implementation for this uses two session beans. The first is a Payment session bean that implements the business logic as appropriate calling entity beans to persist the change. The second is a BatchPayment session bean. This processes the batch of payment transactions received from the bank. The BatchPayment reads through the batch of payments from a bank calling the Payment session bean for each payment transaction.
    Lets look at the transactional properties of both session beans. In order to support the client application the Payment session bean can implicitly enforce transactional integrity and is therefore set to container-managed transaction demarcation. However the BatchPayment session bean will want to explicitly specify transaction demarcation for performance reasons. The transactional "commit" process is relatively expensive. When processing a large batch of transactions rather than performing a commit after every transaction is processed we want to perform the commit after a number of transactions have been processed. For example, we may decide that after every 100 transactions have been processed we commit. The processing will have a shorter elapsed time as we have not had to perform 99 commit processes. So the BatchPayment session bean will want to explicitly specify its transaction demarcation and will therefore be defined with bean-managed transaction demarcation.
    How would this be implemented? A possible solution is:
    Payment session bean implemented with container-managed transaction demarcation with transaction scope set to Required.
    BatchPayment session bean implemented with bean-managed transaction demarcation with transaction scope set to Required.
    When the client application is run it calls the Payment bean and the container-managed transaction demarcation ensures the transactional integrity of that transaction.
    When a BatchPayment process is run it explicitly determines the transaction demarcation. Lets say that after every 100 Payment transactions (through 100 calls to the Payment session bean) have been processed the BatchPayment bean issues a commit. In this scenario however we have mixed container-managed and bean-managed transaction demarcation. Hence my original question. Can container-managed and bean-managed transaction demarcation be mixed? If not how is it possible to implement the requirements as described above?
    Thanks for any thoughts.
    Paul

    BatchPayment session bean implemented with bean-managed transaction demarcation with transaction scope set to Required.Didn't quite understand this sentence.... if it's BMT it has no declarative transaction attributes such as "Required"....
    Anyway, first of all I'll have to ask, Why at all would you want to commit in the middle of the business method? to get as much through as possible before a potential crash? :-)
    Can container-managed and bean-managed transaction demarcation be mixed?Yes, of course. Just remember that the "direction" you are refering to ->
    a BMT SB that propagates it's transaction to a method in a CMT SB that is demarcated with "Required" is the simplest case. If it were "reversed", or for that matter any BMT that might be called within an active transaction context must perform logic to manipulate the transaction state. For instance(and most common case), checking to see if a transaction is active and if so not to do anything(just use the one that is already active).
    If not how is it possible to implement the requirements as described above?You could also implement this scenario with CMTs all the way through. your BatchPayment SB could consist of two methods, one (say, execute(Collection paymentsToExecute) ) with "Supports", and another(say executeBatchUnit(Collection paymentsToExecute, int beginIndex, int endIndex) ) with "RequiresNew".
    then have the first just call the other with indexes denoting each time a group of payments.
    Still, it does seem more suitable using BMT for these kind of things.....
    Hope this helped....

  • Container managed bean persistence queries

    Hi,
    I want to know where the container generated java sources and
    classes for the container managed beans will be sotred as i want
    to look out the sql queries that is not inserting and updating
    the values into the tables.
    As well i want to refer how the bean persistence is handled.
    thanks
    kumar

    Hi,
    I want to know where the container generated java sources and
    classes for the container managed beans will be sotred as i want
    to look out the sql queries that is not inserting and updating
    the values into the tables.
    As well i want to refer how the bean persistence is handled.
    thanks
    kumar

  • Bean-managed persistence (BMP) in EJB 3.0

    I've been on the google for a few days now and haven't found one single notion on bean-managed persistence in EJB 3.0 specification. Even the official specification PDFs don't mention it :(
    Help! I need BMP! Does anybody know what's the situtation in EJB 3.0? Can I and how mark an entity bean to be bean-managed persistent and use ejbLoad and ejbStore functions like in the EJB 2.0 or something like that?
    Tnx in advance,
    Igor

    Tnx Frank, I was afraid of that :(
    I think that is a step back for the EJB technology. Now it is fixed to the table structure, every change in the database calls for a re-desing, re-compilation and re-deplyoment.
    With BMP in EJB 2.1 one was able to build a bean that modifies itself according to the table structure dinamically. Is there any way to do it in EJB 3.0?
    Igor

Maybe you are looking for