1 2 Previous Next 19 Replies Latest reply on Jul 31, 2009 7:36 AM by dhinojosa Go to original post
      • 15. Re: detached entity passed to persist
        damianharvey.damianharvey.gmail.com

        Tony,


        If I'm reading this right, you have a User entity that is stored in the Session context. Sounds like this Wiki page would help.


        As I see it, storing entities in the Session context is a no-no if you intend to operate on them; like the edit that you are performing. The link shows how you can store the ID and then a find() is performed to read the entity into the EntityManager (ie. attach it).


        Cheers,


        Damian.

        • 16. Re: detached entity passed to persist
          tony.herstell1

          Damian Harvey wrote on Feb 29, 2008 11:54 AM:


          Tony,

          If I'm reading this right, you have a User entity that is stored in the Session context. Sounds like this Wiki page would help.

          As I see it, storing entities in the Session context is a no-no if you intend to operate on them; like the edit that you are performing. The link shows how you can store the ID and then a find() is performed to read the entity into the EntityManager (ie. attach it).

          Cheers,

          Damian.




          Up till now I have loved Seam as its SIMPLE TO UNDERSTAND!


          I assumed that you create an Entity or a Bean and you give it a SESSION scope then that bean should stay in its given scope and you read through your current scope and you bump into it in a higher scope... Now you are telling me that the conversation it was constructed in is relevant and has to be considered then I think that is a bad thing for Seam.


          I have not really thought about if any parts of the Entity refer to other Entities in a Conversation scope... I guess I just automatically expect the conversation stuff to vanish after the conversation ends so I would never expect it to be there anyhow.


          I have a cachce bean at Session Level but I read all the bits it needs into the bean (when its initialised) which is in the session scope; so I expect them to stick around (seem to work ok). but even if a Conversation scope bean called into it and caused it to do a read from the database then the result stuff it caches would live in the session scope I hope.


          AFAIK I will code as if the SIMPLE approach is the way its supposed to work and put in the re-read (.find) hack to get round any problems I encounter as it keeps it simple to understand.


          Keep it simple.... anything complicated should be handled by the Seam team... you are the clever guys...


          I have got the stuff working, so far, that I was working on for booking. In that I am seeing the saving and all the bookings in the database and all the parts from 8 collaborating Entities (including Embedded entities) are linking to each other and linking back up to the user object ok... Perhaps I have just been lucky so far.


          Probably not good to write this at 0030! as soo tired from a day fighting with Ajax and Seam.. back to my shovel tomorrow :) Literally! I hope this ramble makes sense.

          • 17. Re: detached entity passed to persist
            damianharvey.damianharvey.gmail.com

            I wonder if you could override the EntityManager to perform a check on any entity that is being persisted/updated/removed and if it is detached, then (re)attach it. That way you wouldn't have to manually code the find(). The entityManager has a contains() method.


            I think this is more an EJB issue than a Seam one as the whole detached concept is JPA. I could be wrong there though.


            Cheers,


            Damian.


            • 18. Re: detached entity passed to persist
              jkronegg
              • 19. Re: detached entity passed to persist
                dhinojosa

                I know it's more than a year later but here is a possible solution

                1 2 Previous Next