Newbie question about EJB-CMP: is it worth it when using multiplecontainers?

Discussion in 'Java' started by Andrea Desole, Nov 4, 2004.

  1. I'm playing around with container managed persistence, and I noticed
    that there is no standard that defines the mapping between beans and
    databases. In fact, this is what the EJB specification says:

    "The Deployer, using the Container Provider s tools, determines how the
    persistent fields and relationships defined by the abstract persistence
    schema are mapped to a database or other persistent store, and generates
    the necessary additional classes and interfaces that enable the
    container to manage the persistent fields and relationships of the
    entity bean instances at runtime."

    If it's true then I will have problems if I have an application that
    supports multiple EJB containers, which is my case. So, my question is:
    isn't it better to write just some normal SQL once and use bean managed
    persistence, instead of writing and maintaining n different files (one
    for each container) for the same mapping? How complex should my SQL be
    to make CMP really valuable in this case?
    Thanks

    Andrea
     
    Andrea Desole, Nov 4, 2004
    #1
    1. Advertising

  2. Re: Newbie question about EJB-CMP: is it worth it when using multiple containers?

    If you really need EJBs use BMP + some OR mapping like hibernate for
    persistance code. But than again - are you sure you need those EJBs anyway?

    "Andrea Desole" <> wrote in message
    news:...
    > I'm playing around with container managed persistence, and I noticed
    > that there is no standard that defines the mapping between beans and
    > databases. In fact, this is what the EJB specification says:
    >
    > "The Deployer, using the Container Provider s tools, determines how the
    > persistent fields and relationships defined by the abstract persistence
    > schema are mapped to a database or other persistent store, and generates
    > the necessary additional classes and interfaces that enable the
    > container to manage the persistent fields and relationships of the
    > entity bean instances at runtime."
    >
    > If it's true then I will have problems if I have an application that
    > supports multiple EJB containers, which is my case. So, my question is:
    > isn't it better to write just some normal SQL once and use bean managed
    > persistence, instead of writing and maintaining n different files (one
    > for each container) for the same mapping? How complex should my SQL be
    > to make CMP really valuable in this case?
    > Thanks
    >
    > Andrea
     
    Eugene Ostroukhov, Nov 4, 2004
    #2
    1. Advertising

  3. Actually, hibernate is not a bad idea. I was not thinking about using it
    with EJBs. I'll look at it.
    I haven't been working for a long time on this application, but I think
    yes, EJBs are needed, since there are more applications talking to each
    other, sometimes on different machines. Having to use a communication
    framework in a Java environment I don't think EJBs are a bad choice.
    Thanks for the tip


    Andrea


    Eugene Ostroukhov wrote:
    > If you really need EJBs use BMP + some OR mapping like hibernate for
    > persistance code. But than again - are you sure you need those EJBs anyway?
    >
    > "Andrea Desole" <> wrote in message
    > news:...
    >
    >>I'm playing around with container managed persistence, and I noticed
    >>that there is no standard that defines the mapping between beans and
    >>databases. In fact, this is what the EJB specification says:
    >>
    >>"The Deployer, using the Container Provider s tools, determines how the
    >>persistent fields and relationships defined by the abstract persistence
    >>schema are mapped to a database or other persistent store, and generates
    >>the necessary additional classes and interfaces that enable the
    >>container to manage the persistent fields and relationships of the
    >>entity bean instances at runtime."
    >>
    >>If it's true then I will have problems if I have an application that
    >>supports multiple EJB containers, which is my case. So, my question is:
    >>isn't it better to write just some normal SQL once and use bean managed
    >>persistence, instead of writing and maintaining n different files (one
    >>for each container) for the same mapping? How complex should my SQL be
    >>to make CMP really valuable in this case?
    >>Thanks
    >>
    >>Andrea

    >
    >
    >
     
    Andrea Desole, Nov 4, 2004
    #3
  4. Andrea Desole

    Chris Smith Guest

    Re: Newbie question about EJB-CMP: is it worth it when using multiple containers?

    Andrea Desole wrote:
    > I'm playing around with container managed persistence, and I noticed
    > that there is no standard that defines the mapping between beans and
    > databases. In fact, this is what the EJB specification says:


    [...]

    > If it's true then I will have problems if I have an application that
    > supports multiple EJB containers, which is my case.


    You should be aware that the EHB specification was not written to allow
    randomly swapping the EJB container. The claim is that it was, but the
    reality is that various companies have a financial interest in
    encouraging you to buy into their platform as opposed to another, so a
    lot of the EJB spec is left up to the implementation or limited to the
    point that you're sometimes forced to rely on vendor extensions. EJB is
    a lot like SQL in this respect; it's possible to write portable code,
    but only if you don't have particularly advanced needs.

    So if you need to depend on the database schema from outside basic use
    of your CMP EJBs, then you've run into such a limitation. You can use
    BMP EJBs, perhaps with Hibernate as someone else suggested, or you can
    research each of your possible containers and determine how they do the
    persistence mapping, and then try to adapt all of them to one schema.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Nov 4, 2004
    #4

  5. > You should be aware that the EHB specification was not written to allow
    > randomly swapping the EJB container. The claim is that it was, but the
    > reality is that various companies have a financial interest in
    > encouraging you to buy into their platform as opposed to another, so a
    > lot of the EJB spec is left up to the implementation or limited to the
    > point that you're sometimes forced to rely on vendor extensions. EJB is
    > a lot like SQL in this respect; it's possible to write portable code,
    > but only if you don't have particularly advanced needs.


    mmmmm, this is not really the concept of "write once run anywhere" I had
    in mind :)


    >
    > So if you need to depend on the database schema from outside basic use
    > of your CMP EJBs, then you've run into such a limitation. You can use
    > BMP EJBs, perhaps with Hibernate as someone else suggested, or you can
    > research each of your possible containers and determine how they do the
    > persistence mapping, and then try to adapt all of them to one schema.
    >


    I have to say that, after a further discussion, I now know that a reason
    to use EJBs is also that EJBs allow a better control in the case that an
    object changes, because a notification is sent, so that all the other
    instances, on other machines (in case, for example, of a cluster) can be
    updated. I'm not sure Hibernate can do that, and I'm not sure it's
    possible to find a good framework that can (maybe JDO?)
    Maybe the best option is really to use plain BMP and SQL.
     
    Andrea Desole, Nov 4, 2004
    #5
  6. Andrea Desole

    Sudsy Guest

    Andrea Desole wrote:
    <snip>
    > If it's true then I will have problems if I have an application that
    > supports multiple EJB containers, which is my case. So, my question is:
    > isn't it better to write just some normal SQL once and use bean managed
    > persistence, instead of writing and maintaining n different files (one
    > for each container) for the same mapping? How complex should my SQL be
    > to make CMP really valuable in this case?


    CMP EJBs are just another abstraction layer atop proprietary RDBMS
    interfaces. You write your queries in EJB QL rather than SQL and the
    mapping to the underlying data source is typically performed at
    deployment time.
    If you're performing complex transactions across multiple data
    sources then the J2EE features really come into play. CMR and the
    "order by" clause (missing from the first version) handle much of
    the complexity you would have to manage explicitly with BMP.
    IMHO it depends on the complexity of your app. There are certainly
    alternatives; DAOFactory immediately comes to mind. Once you get to
    a point where you're explicitly managing transactions and relation-
    ships, you might have reached the juncture where CMPs can simplify
    your life (not to mention your coding ;-).

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
     
    Sudsy, Nov 4, 2004
    #6
  7. Sudsy wrote:
    > Andrea Desole wrote:
    > <snip>
    >
    >> If it's true then I will have problems if I have an application that
    >> supports multiple EJB containers, which is my case. So, my question
    >> is: isn't it better to write just some normal SQL once and use bean
    >> managed persistence, instead of writing and maintaining n different
    >> files (one for each container) for the same mapping? How complex
    >> should my SQL be to make CMP really valuable in this case?

    >
    >
    > CMP EJBs are just another abstraction layer atop proprietary RDBMS
    > interfaces. You write your queries in EJB QL rather than SQL and the
    > mapping to the underlying data source is typically performed at
    > deployment time.


    true. It's also true that I can create/update/delete with almost no
    effort. But the problem with n different configuration files for n
    different containers still persists. And most of the times, when I have
    to implement CRUD operations or similar, I can use SQL that very likely
    will be understood by most RDBMS.


    > If you're performing complex transactions across multiple data
    > sources then the J2EE features really come into play. CMR and the
    > "order by" clause (missing from the first version) handle much of
    > the complexity you would have to manage explicitly with BMP.
    > IMHO it depends on the complexity of your app. There are certainly
    > alternatives; DAOFactory immediately comes to mind. Once you get to
    > a point where you're explicitly managing transactions and relation-
    > ships, you might have reached the juncture where CMPs can simplify
    > your life (not to mention your coding ;-).
    >
     
    Andrea Desole, Nov 4, 2004
    #7
  8. >
    > I have to say that, after a further discussion, I now know that a reason
    > to use EJBs is also that EJBs allow a better control in the case that an
    > object changes, because a notification is sent, so that all the other
    > instances, on other machines (in case, for example, of a cluster) can be
    > updated. I'm not sure Hibernate can do that, and I'm not sure it's
    > possible to find a good framework that can (maybe JDO?)


    never mind, I think I got the point.
    The idea is to use Hibernate as a lower layer for the EJBs, so the EJBs
    can be regularly used.
    Thanks

    Andrea
     
    Andrea Desole, Nov 4, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Tyson
    Replies:
    0
    Views:
    396
    Andrew Tyson
    Jul 15, 2003
  2. Andrea Sansottera

    no cmp field defined in cmp ejb

    Andrea Sansottera, Jul 16, 2004, in forum: Java
    Replies:
    0
    Views:
    402
    Andrea Sansottera
    Jul 16, 2004
  3. Phoenix Silver
    Replies:
    0
    Views:
    379
    Phoenix Silver
    Mar 21, 2005
  4. Donkey Hot

    EJB/CMP entity bean question

    Donkey Hot, May 27, 2008, in forum: Java
    Replies:
    3
    Views:
    465
    Arved Sandstrom
    May 29, 2008
  5. Raymond Schanks
    Replies:
    0
    Views:
    672
    Raymond Schanks
    Aug 3, 2010
Loading...

Share This Page