4 Replies Latest reply on Oct 23, 2007 7:42 AM by Pete Muir

    Should you allow @Name on entity beans?

    Samuel Doyle Apprentice

      By doing this it makes it easier to do things like embed logic into entity beans which is not their intended use. A colleague of mine who is brand new to EJB3 and Seam did that just the other day and I was like wow, that is pretty odd.

      Unless there are some good use cases for doing this perhaps you guys should disallow this or perhaps throw are verbose warning or something?

      Just a thought.

      S.D.

        • 1. Re: Should you allow @Name on entity beans?
          Dan Allen Master

          The @Name on entity classes is already handled as a special case. Method interception is disabled. Here is what the @Name gives you for entity classes:

          1. give access to entity class via a context variable name for convenience of capturing form data related to the entity without needing to do a factory or other type of initialization

          2. allow a default scope to be assigned so that, again, you don't have to do special factory stuff to get a fresh entity instance in conversation scope (which is the default)

          3. ability to create a prototype of an entity class using component configuration (configure the properties in components.xml)

          I don't think there is any harm in doing it. Whether or not you choose to make your entity classes Seam components by giving them a @Name annotation is up to you. If you don't use the @Name annotation, you can always do the same thing via XML in components.xml. There really is no harm in doing so.

          Remember, entity class components are restricted components in that they have:

          no bijection
          no transactions
          no event handling
          etc.

          • 2. Re: Should you allow @Name on entity beans?
            Samuel Doyle Apprentice

            Hello Dan and thanks for the clarification.

            I'm still myself fairly new to Seam myself but we are considering using it in two new projects based on successful results in prototyping.

            Do you know anything about the status of the server side push JavaScript Remoting capability provided by Seam? The last I read was that it was still experimental. The regular remoting works great however we are looking at requirements that suggest using a push would be a better approach. For the time being until Seam has official support for this we are using DWR.

            Thanks, S.D.

            • 3. Re: Should you allow @Name on entity beans?
              Nicklas Karlsson Master

               

              "samdoyle" wrote:
              By doing this it makes it easier to do things like embed logic into entity beans which is not their intended use. A colleague of mine who is brand new to EJB3 and Seam did that just the other day and I was like wow, that is pretty odd.


              I would have to strongishly disagree (although I know this is a religious issue). I think logic *should* be in the entity beans. Most definitions of object-oriented design goes something like

              "Each class encapsulates some data and all operations upon that data".

              Personally I try to avoid using entity beans as dumb DTO:s. It seems so pre-EJB3:ish. "Why do we need a DTO?" "Hmm. Because we always have had them. Now be quiet and code" :-)

              Yes. If an entity needs data, I pass in a repository so that it can use it itself (or even have the method lookup the repository itself) instead of having someone else do it and pass in the data.

              • 4. Re: Should you allow @Name on entity beans?
                Pete Muir Master

                I would avoid putting @Name on entity beans.

                1) It's not good if you decide to cluster your app
                2) I find the lifecycle easier to understand if I use a factory (really easy via components.xml)
                3) I find it provides a simpler architecture.