3 Replies Latest reply on Jul 31, 2007 3:48 AM by None None

    Design question: Why use @Name on Entities?

    None None Master

      Simple question: I'm using EntityHome objects to manage a bunch of entities. Therefore I have FooHome to manage Foos, etc. Of course FooHome has to have a @Name annotation:

      @Name("fooHome")


      for it to be a Seam component.

      I can do all my stuff to Foos using fooHome.instance. And if I want to refer to "foo" by itself I can do that by adding an alias in components.xml.

      So... at that point, is there any reason for me to put a @Name annotation on the Foo entity itself?


        • 1. Re: Design question: Why use @Name on Entities?
          Ricardo Memoria Novice

          In my app I have an entity that is a session component.

          This entity holds information about the user login (like ip address, connection date and time, etc) and is "persisted" by the authenticator bean.

          After that it's just read by the app and never changed again.

          Ok... I could have used an EntityHome, but it would requires me a few aditional lines of code.

          regards,
          Ricardo Memória

          • 2. Re: Design question: Why use @Name on Entities?
            Norman Richards Master

            I can't think of any compelling cases where @Name is the best choice for an entity. If the entity only has one role, with no special creation logic (pre-configuration of attributes in components.xml) then it's a bit simpler just to use @Name.

            • 3. Re: Design question: Why use @Name on Entities?
              None None Master

              Thanks for the info. I saw examples where the entities had @Name notations on them, so I started doing that, but that actually caused me a lot of confusion. When I use an outjection I can control the scope of components which are not @Named entities, but if it is @Named then the @Name setting controls the scope... that confused me a lot. It seems easier to just not put a @Name on the various entities, and use @Name only for actions. Then if I want to alias something I'll do that in components.xml, but I don't even need to do that. I would prefer to access userHome.instance instead of just user, because to me there's less ambiguity about which user I'm talking about with userHome.instance.

              Thanks for clearing this up.