• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a very noobish EJB question

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using session beans to perform my business logic and what not. So in my session bean I will have a method that looks something like:



Then in my Name bean, I will have something that looks like this:


Now, here is where I have my question. In my DAO class, I have the findByName method defined, I do my sql select to retrieve the appropriate record from the database. Now, do I have to create a helper class to load the needed data in to, and add that to my collection to be returned? OR do actually return a collection of Name EJBs?

If both ways are possible, what is the 'preferred, professional or correct(according the the J2EE spec)' method of doing this?

TIA
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I were to use a finder method, I would use it as a method in an entity bean's home. However, if I were to use a DAO, I would use the DAO from a session bean directly.

At the class level, you might want to insert something like:


You'd probably need to insert other container-specific tags. For JBoss, I insert at the class level :



Make sure you have the same names in your descriptor xml files.

At the method level of your finder method, you may wish to insert something like:

findItems is a method in the DAO class.

TUSC has a tutorial which your design is similar to. Chp 3 & 4 explains how to use DAO for stateless and stateful session beans respectively. Click
here.

Originally posted by Matt Sloan:
I am using session beans to perform my business logic and what not. So in my session bean I will have a method that looks something like:



Then in my Name bean, I will have something that looks like this:


Now, here is where I have my question. In my DAO class, I have the findByName method defined, I do my sql select to retrieve the appropriate record from the database. Now, do I have to create a helper class to load the needed data in to, and add that to my collection to be returned? OR do actually return a collection of Name EJBs?

If both ways are possible, what is the 'preferred, professional or correct(according the the J2EE spec)' method of doing this?

TIA

 
Matt Sloan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok still a bit confused.

The requirements are that this app use entity EJBs - I am thinking BMP beans since we already have all the needed sql written in a giant DAO class. We are using session beans to use the home interface and call whatever method needed - in this case findByName(name). What happens in the Name bean is we call the dao which returns a collection of plain java objects. I am wondering if we are doing it wrong - instead of the plain java objects, shouldn't we be returning a collection of ejbs?
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The requirements are that this app use entity EJBs - I am thinking BMP beans since we already have all the needed sql written in a giant DAO class.


You might know that whatever has been delivered today might need to be refactored tomorrow. I understand that reusing your DAO might save you some time and trouble, but they might be some other good reason for you to go actually with CMP. Think twice before going this path, because is very possible that the persistence solution you�ll deliver might be less performant than the original one that used DAOs and POJOs. One reason that makes me say that is the infamous n+1 selects statements problem with entity ejbs, but they could be many others. Good containers, like weblogic for example provides a lot of vendor specific features that enhance your CMP ejbs (like caching between transactions, readonly ejbs, multiple-table mapping support, dynamic query support, automatic pk generation, etc).


in this case findByName(name). What happens in the Name bean is we call the dao which returns a collection of plain java objects. I am wondering if we are doing it wrong - instead of the plain java objects, shouldn't we be returning a collection of ejbs?


You have to return a collection of primary keys.
Regards.
 
Matt Sloan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Valentin Tanase:

You have to return a collection of primary keys.



This just blew my mind. If I return only the primary key, how do I get the data that is tied to that primary key?
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't worry. Your home will return a collection containing either the remote or the local interface of your entity beans just the same. You can get your data from that interface.

Would it be better if you go through the tutorial in tusc ? In no time, you'll find yourself skipping this current problem and into the many others waiting right around the corner. Those are the ones you'll need to worry about. I know I did !

Originally posted by Matt Sloan:


This just blew my mind. If I return only the primary key, how do I get the data that is tied to that primary key?

 
Matt Sloan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help - I am starting on the tutorial now - and thanks for the heads up on what waits for me around the corner.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matt,

Have you started the TUSC tutorial?

I am intrested in doing this tutorial.
am stuck with some setup on chapter 2.

In classpath_variable , on my eclipse I see JRE_SRC as empty where as , as per the tutorial it is having value where src.zip file is saved.

What installation gets src.zip on your machine? I dont find any on my machine.

Can someone help me with this?
Thanks,
Gemini
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check if you have already got the src.zip in your JDK. A full download should have the file. It contains the jdk source code for Eclipse to take you to when you're in debug mode.

If yes, you need to point the variable jre_src to the file.

Originally posted by Gemini Moses:
Matt,

Have you started the TUSC tutorial?

I am intrested in doing this tutorial.
am stuck with some setup on chapter 2.

In classpath_variable , on my eclipse I see JRE_SRC as empty where as , as per the tutorial it is having value where src.zip file is saved.

What installation gets src.zip on your machine? I dont find any on my machine.

Can someone help me with this?
Thanks,
Gemini

 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ken for your reply.

I do not have src.zip onmy machine.

I have installed Eclipse using
eclipse-SDK-2.1-win32.zip

I also installed ,
j2eesdk-1_4-windows.exe

I am instrested in doing this application and not enjoying getting stuck with this set up stuff

Can someone give me exact links of files that I should be installing.
I am ready to uninstall everything and start again.

Awaiting reply..
Gemini
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt,


The requirements are that this app use entity EJBs - I am thinking BMP beans since we already have all the needed sql written in a giant DAO class.



Since you've to use entity beans, I'd you use CMP instead of BMP. You could use EJB-QL instead of writing SQL.

If you have the option not to use entity beans, then perhaps you could use an ORM tools such as Apache's OJB or Hibernate. Both are open-source & have tutorials to get you started. You could still use your session beans as a facade & then call the ORM's API to help you with your CRUD by using the POJOs.

Returning a collection of entity beans to your client incurs overhead. Its far better for you to be returning a collection of POJOs. Although, you could face stale data situations.

HTH.
 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt,

The way you're using your POJOs is explained in the Transfer Object(TO) pattern. I'm using this pattern extensively for viewable-only and paginable list of objects, and absolutely have no complaints about it. I agree with Chengwei on the point on using TOs in place of entity beans' remote interface.

However, do consider Valentin's advice on using CMP to leverage the good stuff that a container provides if they are warranted for your case. You are the best person to judge.


Originally posted by Matt Sloan:
Ok still a bit confused.

The requirements are that this app use entity EJBs - I am thinking BMP beans since we already have all the needed sql written in a giant DAO class. We are using session beans to use the home interface and call whatever method needed - in this case findByName(name). What happens in the Name bean is we call the dao which returns a collection of plain java objects. I am wondering if we are doing it wrong - instead of the plain java objects, shouldn't we be returning a collection of ejbs?

 
Ken Loh
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll be happier if you take the installation process as the Baptism of Fire of becoming a J2EE programmer.

What you can do are :
  • google the j2sdk's download file in Sun's website;
  • download the zipped file;
  • unzip the file to find src.zip;
  • put src.zip to a folder of your liking; and
  • set JRE_SRC of you Eclipse to the folder,


  • You'd be glad to know that these steps would probably take the same amount of time for you to type your previous posting.

    Originally posted by Gemini Moses:
    Thanks Ken for your reply.

    I do not have src.zip onmy machine.

    I have installed Eclipse using
    eclipse-SDK-2.1-win32.zip

    I also installed ,
    j2eesdk-1_4-windows.exe

    I am instrested in doing this application and not enjoying getting stuck with this set up stuff

    Can someone give me exact links of files that I should be installing.
    I am ready to uninstall everything and start again.

    Awaiting reply..
    Gemini


    [ April 14, 2005: Message edited by: Ken Loh ]
     
    Ken Loh
    Ranch Hand
    Posts: 190
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Can't help from looking up for the site to get the source code. Here it is:
    http://www.sun.com/software/communitysource/j2se/java2/download.xml
    reply
      Bookmark Topic Watch Topic
    • New Topic