[jboss-user] [JBoss Seam] - Re: Basic Seam questions

SmokingAPipe do-not-reply at jboss.com
Tue Dec 12 03:25:38 EST 2006


There are subtle differences here.  I'll go through your post sentence-by-sentence.

When you inject an entity into a session, you could get an instance that already exists.  For example, here's injection:

@In User user;

and here's instantiating it manually:

User user = new User();

These do totally different things.  In the injection case, we'll be getting the user, perhaps from the SESSION scope, and so we can do things with it.  In the "instantiating manually" case we make up a new one every time.  Do you see the difference?  They are for different purposes.

@In(create=true) will inject the entity if it can be found in the relevant scope, and creates it if it isn't there.  When wouldn't you want to have create=true?  Imagine a typical application where a User object is stored in the SESSION scope.  If there is no user in that scope, we might leave out certain functionality.  Creating a new user instance wouldn't make sense.

Does this make sense?  Think of your session beans as being parts of an assembly line.  Various objects get injected into them, they do things to these objects, and then they can outject results.  If a certain part on this assembly line requires an object that isn't there, it could (unlike in a real assembly line) create the object by saying create=true.  Or if it will ALWAYS create its own objects for its own use it could simply instantiate them.  But this means that it will not get objects that have been outjected by some other component, and the power of Seam is really being able to tie these various components together by outjecting from one and injecting to the other.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3992985#3992985

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3992985



More information about the jboss-user mailing list