• Post Reply Bookmark Topic Watch Topic
  • New Topic

A newbie j2ee question  RSS feed

 
Moje Ime
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new to j2ee, and i find it very confusing..i am working in a company where we use seam, jboss, EJB, hibernate,jbpm,jsf,javascript and others...I read some of the books about it...but it is almost impossible to read all those books in such a short notice...(we need to finish the project very soon).

I am kinda getting the hang of it, through work..but i must confess it is not an easy job.

One of the things i haven't figured out yet is this.

Sometimes we inject a value into the property of the certain class by using seam's annotation @In, and sometimes we use @EJB...I haven't figured out when we use one and when the other.

Example:

@Name("businessProcessManager")
@Stateless
public class BusinessProcessManagerBean implements BusinessProcessManager{
...
}


Is used in another bean with the following code...

@Name("complainProcessFacade")
@Stateless
public class ComplainProcessFacadeBean implements ComplainProcessFacade
{

@EJB
private BusinessProcessManager businessProcessManager;
...
}

Why did the guy used @EJB on the businessProcessManager in complainprocessfacadebean? Couldn't he have used @In since it has a @Name (so it is a seams component too)???
What am i missing here???

Thanks in advance!
 
Krum Bakalsky
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't want to be rude, but, assuming that i have had only JavaSE exposure so far, if i had to be literate in all the mentioned technologies by you, it would take me at least a couple of months of hard home preparation of at least 8 hours a day....

Hurrying up to catch deadlines and using complex JavaEE architectural design, can lead you to nothing but a total mess and chaos in your head.

Good luck to you!
 
Moje Ime
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure i understand what was the purpose of your post, but thanks anyways.

In the meantime i have found out the part of the answer.

We need to use "@In" in stateless beans when we want to use fields that are bound to stateful objects. The @EJB annotation cannot help us because of the way it works (it is not designed to inject stateful object references in a stateless bean). However Seam can make it work with it's internal interceptor mechanisms (interceptor will inject values from the context into the stateless session EJB, invoke the EJB method, then outject any values back into the context thus leaving it stateless).

The question remains why we don't use @In all the time, since it is definitely superior. My guess is, that @In adds complexity and slows down the execution of the application, so it needs to be used with caution. If somebody can add to this please do.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moje Ime wrote:

We need to use "@In" in stateless beans when we want to use fields that are bound to stateful objects. The @EJB annotation cannot help us because of the way it works (it is not designed to inject stateful object references in a stateless bean). However Seam can make it work with it's internal interceptor mechanisms (interceptor will inject values from the context into the stateless session EJB, invoke the EJB method, then outject any values back into the context thus leaving it stateless).

Although that might apply to the specific usecase you are considering in your application, it's not always true. @EJB is a JavaEE standard specified annotation and will work in all application servers which are JavaEE certified. @In is Seam specific annotation. Seam is an application framework and outside of Seam, @In annotation will not hold any meaning to other component framework which will do the injection (unless maybe those frameworks are based on Seam). But again, that's the general case I am talking about. It doesn't answer why some places of your application uses @EJB and some places @In - the answer to that can only be found by looking at the code and the context in which that piece of code runs.

Moje Ime wrote:
The question remains why we don't use @In all the time, since it is definitely superior. My guess is, that @In adds complexity and slows down the execution of the application, so it needs to be used with caution. If somebody can add to this please do.

As I said, it depends on the code context where it's being used. As for the @In complexity and slow execution, from what I read of that annotation, I don't see that as the reason.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important point which I forgot to add in my previous reply. The @In can inject any component which is Seam manages. On the other hand, @EJB can only be used to inject EJBs
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!