aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes a very noobish EJB question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "a very noobish EJB question" Watch "a very noobish EJB question" New topic
Author

a very noobish EJB question

Matt Sloan
Greenhorn

Joined: Aug 12, 2002
Posts: 7
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
Ken Loh
Ranch Hand

Joined: Feb 16, 2005
Posts: 190
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

Joined: Aug 12, 2002
Posts: 7
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?
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704

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.


I think, therefore I exist -- Rene Descartes
Matt Sloan
Greenhorn

Joined: Aug 12, 2002
Posts: 7
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

Joined: Feb 16, 2005
Posts: 190
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

Joined: Aug 12, 2002
Posts: 7
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.
Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
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

Joined: Feb 16, 2005
Posts: 190
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

Joined: Jan 04, 2001
Posts: 245
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
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
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.


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Ken Loh
Ranch Hand

Joined: Feb 16, 2005
Posts: 190
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

Joined: Feb 16, 2005
Posts: 190
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

    Joined: Feb 16, 2005
    Posts: 190
    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
     
     
    subject: a very noobish EJB question