I think you're biggest problem is you haven't gotten your head wrapped around the
conversational model yet. It definitely takes time and I'd recommend that the first
thing you do is at least skim through the Seam reference documentation in it's
entirety.
That being said, I'll try to explain as best I can.
anonymous wrote : I don't understand this part at all. I know that if I stick the
edited activity back into the users collection of activites and have the correct cascade
type, that when I save the updated user, it will save the updated activity as well.
Where you're going wrong here is you don't need to stick the activity back into
the list if it's already there. If you are using a conversationally scoped EM (which
is what my suggestions are based on) then there will only be one version of each activity
per conversation, whether that activity was retrieved through user.getActivities or
through SELECT..... That's how an EntityManager works and it's important to
understand that. So rather than the view that you provided, what I'm talking about is
the edit view where you will have values bound like:
| Name: <h:inputText value="#{selectedActivity.name}"/>
|
When the update data model phase happens the name would be updated on the one and only
version of the selected Activity, which is managed by your conversation scoped EM, and
when the transaction is commited it will be updated. After that anytime you access
user.getActivities() you will see the updated activity and it will be reflected in the
database. Does that make more sense?
anonymous wrote : I guess that's what I'm saying. I'm not sure I'd call it
spanning more than one conversation. In reality, user is a session scoped bean
representing the currently logged in user.
Well, since a session may contain many conversations, then your User object at least has
the capability of spanning more than one and that should be factored in. Again, this
seems to be an issue with your understanding of how conversations, and more specifically
conversation scoped EMs work. You cannot use the @PersistenceContext annotation to
specify a conversation scoped EM. It needs to be injected using the @In annotation, and
if you've configured that correctly (see the docs on how) Seam will magically make
sure that the same EM gets injected into every bean within the same conversation.
As far as persistence units are concerned, I've never had the need to deal with more
than one on a project, but I'd imagine if I did I could create 2 Seam managed EMs, one
for each persistence context and then your example would become:
| @In(create="true")
| EntityManager manager1;
|
| @In(create="true")
| EntityManager manager2;
|
Where manager1 and manager2 are both properly configured, conversation scoped EMs.
Make more sense?
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983934#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...